diff --git a/src/Graphics.h b/src/Graphics.h index bd88d59f2..e4c2ad8d2 100644 --- a/src/Graphics.h +++ b/src/Graphics.h @@ -4,7 +4,7 @@ #include #include #include -#if defined(OGLR) +#if defined(OGLI) #include "OpenGLHeaders.h" #endif #include "Config.h" @@ -104,7 +104,7 @@ class Graphics public: pixel *vid; int sdl_scale; -#ifdef OGLR +#ifdef OGLI //OpenGL specific instance variables GLuint vidBuf, textTexture; #endif diff --git a/src/OpenGLGraphics.cpp b/src/OpenGLGraphics.cpp index b7d479559..eb242ce3b 100644 --- a/src/OpenGLGraphics.cpp +++ b/src/OpenGLGraphics.cpp @@ -1,7 +1,7 @@ #include "Graphics.h" #include "font.h" -#ifdef OGLR +#ifdef OGLI Graphics::Graphics(): sdl_scale(1) diff --git a/src/PixelMethods.inc b/src/PixelMethods.inc new file mode 100644 index 000000000..eff0b6039 --- /dev/null +++ b/src/PixelMethods.inc @@ -0,0 +1,332 @@ +#include "font.h" + +int PIXELMETHODS_CLASS::drawtext(int x, int y, const char *s, int r, int g, int b, int a) +{ + if(!strlen(s)) + return 0; + int width, height; + + int characterX = x, characterY = y; + int startX = characterX; + for (; *s; s++) + { + if (*s == '\n') + { + characterX = startX; + characterY += FONT_H+2; + } + else if (*s == '\b') + { + switch (s[1]) + { + case 'w': + r = g = b = 255; + break; + case 'g': + r = g = b = 192; + break; + case 'o': + r = 255; + g = 216; + b = 32; + break; + case 'r': + r = 255; + g = b = 0; + break; + case 'l': + r = 255; + g = b = 75; + break; + case 'b': + r = g = 0; + b = 255; + break; + case 't': + b = 255; + g = 170; + r = 32; + break; + } + s++; + } + else + { + characterX = drawchar(characterX, characterY, *(unsigned char *)s, r, g, b, a); + } + } + return x; +} + +int PIXELMETHODS_CLASS::drawtext(int x, int y, std::string s, int r, int g, int b, int a) +{ + return drawtext(x, y, s.c_str(), r, g, b, a); +} + +TPT_INLINE int PIXELMETHODS_CLASS::drawchar(int x, int y, int c, int r, int g, int b, int a) +{ + int i, j, w, bn = 0, ba = 0; + char *rp = font_data + font_ptrs[c]; + w = *(rp++); + for (j=0; j>= 2; + bn -= 2; + } + return x + w; +} + +TPT_INLINE int PIXELMETHODS_CLASS::addchar(int x, int y, int c, int r, int g, int b, int a) +{ + int i, j, w, bn = 0, ba = 0; + char *rp = font_data + font_ptrs[c]; + w = *(rp++); + for (j=0; j>= 2; + bn -= 2; + } + return x + w; +} + +TPT_INLINE void PIXELMETHODS_CLASS::xor_pixel(int x, int y) +{ + int c; + if (x<0 || y<0 || x>=XRES || y>=YRES) + return; + c = vid[y*(VIDXRES)+x]; + c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c); + if (c<512) + vid[y*(VIDXRES)+x] = PIXPACK(0xC0C0C0); + else + vid[y*(VIDXRES)+x] = PIXPACK(0x404040); +} + +TPT_INLINE void PIXELMETHODS_CLASS::blendpixel(int x, int y, int r, int g, int b, int a) +{ + pixel t; + if (x<0 || y<0 || x>=VIDXRES || y>=VIDYRES) + return; + if (a!=255) + { + t = vid[y*(VIDXRES)+x]; + r = (a*r + (255-a)*PIXR(t)) >> 8; + g = (a*g + (255-a)*PIXG(t)) >> 8; + b = (a*b + (255-a)*PIXB(t)) >> 8; + } + vid[y*(VIDXRES)+x] = PIXRGB(r,g,b); +} + +TPT_INLINE void PIXELMETHODS_CLASS::addpixel(int x, int y, int r, int g, int b, int a) +{ + pixel t; + if (x<0 || y<0 || x>=VIDXRES || y>=VIDYRES) + return; + t = vid[y*(VIDXRES)+x]; + r = (a*r + 255*PIXR(t)) >> 8; + g = (a*g + 255*PIXG(t)) >> 8; + b = (a*b + 255*PIXB(t)) >> 8; + if (r>255) + r = 255; + if (g>255) + g = 255; + if (b>255) + b = 255; + vid[y*(VIDXRES)+x] = PIXRGB(r,g,b); +} + +void PIXELMETHODS_CLASS::xor_line(int x1, int y1, int x2, int y2) +{ + int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; + float e, de; + if (cp) + { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if (x1 > x2) + { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if (dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) + { + y += sy; + e -= 1.0f; + } + } +} + +void PIXELMETHODS_CLASS::xor_rect(int x, int y, int w, int h) +{ + int i; + for (i=0; iabs(x2-x1), x, y, dx, dy, sy; + float e, de; + if (cp) + { + y = x1; + x1 = y1; + y1 = y; + y = x2; + x2 = y2; + y2 = y; + } + if (x1 > x2) + { + y = x1; + x1 = x2; + x2 = y; + y = y1; + y1 = y2; + y2 = y; + } + dx = x2 - x1; + dy = abs(y2 - y1); + e = 0.0f; + if (dx) + de = dy/(float)dx; + else + de = 0.0f; + y = y1; + sy = (y1= 0.5f) + { + y += sy; + e -= 1.0f; + } + } +} + +void PIXELMETHODS_CLASS::drawrect(int x, int y, int w, int h, int r, int g, int b, int a) +{ + int i; + w--; + h--; + for (i=0; i<=w; i++) + { + blendpixel(x+i, y, r, g, b, a); + blendpixel(x+i, y+h, r, g, b, a); + } + for (i=1; i VIDYRES) h = (VIDYRES)-y; //Adjust height to prevent drawing off the bottom + if(a >= 255) + for (j=0; jTick(); engine->Draw(); - if(SDL_GetTicks()-lastTick>1000) + if(SDL_GetTicks()-lastTick>500) { //Run client tick every second lastTick = SDL_GetTicks(); Client::Ref().Tick(); } -#ifdef OGLR +#ifdef OGLI blit(); #else blit(engine->g->vid); diff --git a/src/RasterGraphics.cpp b/src/RasterGraphics.cpp index b807238f2..31b1b974f 100644 --- a/src/RasterGraphics.cpp +++ b/src/RasterGraphics.cpp @@ -1,7 +1,6 @@ #include "Graphics.h" -#include "font.h" -#ifndef OGLR +#ifndef OGLI Graphics::Graphics(): sdl_scale(1) @@ -25,335 +24,12 @@ void Graphics::Finalise() } -int Graphics::drawtext(int x, int y, const char *s, int r, int g, int b, int a) -{ - if(!strlen(s)) - return 0; - int width, height; - - int characterX = x, characterY = y; - int startX = characterX; - for (; *s; s++) - { - if (*s == '\n') - { - characterX = startX; - characterY += FONT_H+2; - } - else if (*s == '\b') - { - switch (s[1]) - { - case 'w': - r = g = b = 255; - break; - case 'g': - r = g = b = 192; - break; - case 'o': - r = 255; - g = 216; - b = 32; - break; - case 'r': - r = 255; - g = b = 0; - break; - case 'l': - r = 255; - g = b = 75; - break; - case 'b': - r = g = 0; - b = 255; - break; - case 't': - b = 255; - g = 170; - r = 32; - break; - } - s++; - } - else - { - characterX = drawchar(characterX, characterY, *(unsigned char *)s, r, g, b, a); - } - } - return x; -} - -int Graphics::drawtext(int x, int y, std::string s, int r, int g, int b, int a) -{ - return drawtext(x, y, s.c_str(), r, g, b, a); -} - -TPT_INLINE int Graphics::drawchar(int x, int y, int c, int r, int g, int b, int a) -{ - int i, j, w, bn = 0, ba = 0; - char *rp = font_data + font_ptrs[c]; - w = *(rp++); - for (j=0; j>= 2; - bn -= 2; - } - return x + w; -} - -TPT_INLINE int Graphics::addchar(int x, int y, int c, int r, int g, int b, int a) -{ - int i, j, w, bn = 0, ba = 0; - char *rp = font_data + font_ptrs[c]; - w = *(rp++); - for (j=0; j>= 2; - bn -= 2; - } - return x + w; -} - -TPT_INLINE void Graphics::xor_pixel(int x, int y) -{ - int c; - if (x<0 || y<0 || x>=XRES || y>=YRES) - return; - c = vid[y*(XRES+BARSIZE)+x]; - c = PIXB(c) + 3*PIXG(c) + 2*PIXR(c); - if (c<512) - vid[y*(XRES+BARSIZE)+x] = PIXPACK(0xC0C0C0); - else - vid[y*(XRES+BARSIZE)+x] = PIXPACK(0x404040); -} - -TPT_INLINE void Graphics::blendpixel(int x, int y, int r, int g, int b, int a) -{ - pixel t; - if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE) - return; - if (a!=255) - { - t = vid[y*(XRES+BARSIZE)+x]; - r = (a*r + (255-a)*PIXR(t)) >> 8; - g = (a*g + (255-a)*PIXG(t)) >> 8; - b = (a*b + (255-a)*PIXB(t)) >> 8; - } - vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b); -} - -TPT_INLINE void Graphics::addpixel(int x, int y, int r, int g, int b, int a) -{ - pixel t; - if (x<0 || y<0 || x>=XRES+BARSIZE || y>=YRES+MENUSIZE) - return; - t = vid[y*(XRES+BARSIZE)+x]; - r = (a*r + 255*PIXR(t)) >> 8; - g = (a*g + 255*PIXG(t)) >> 8; - b = (a*b + 255*PIXB(t)) >> 8; - if (r>255) - r = 255; - if (g>255) - g = 255; - if (b>255) - b = 255; - vid[y*(XRES+BARSIZE)+x] = PIXRGB(r,g,b); -} - -void Graphics::xor_line(int x1, int y1, int x2, int y2) -{ - int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; - float e, de; - if (cp) - { - y = x1; - x1 = y1; - y1 = y; - y = x2; - x2 = y2; - y2 = y; - } - if (x1 > x2) - { - y = x1; - x1 = x2; - x2 = y; - y = y1; - y1 = y2; - y2 = y; - } - dx = x2 - x1; - dy = abs(y2 - y1); - e = 0.0f; - if (dx) - de = dy/(float)dx; - else - de = 0.0f; - y = y1; - sy = (y1= 0.5f) - { - y += sy; - e -= 1.0f; - } - } -} - -void Graphics::xor_rect(int x, int y, int w, int h) -{ - int i; - for (i=0; iabs(x2-x1), x, y, dx, dy, sy; - float e, de; - if (cp) - { - y = x1; - x1 = y1; - y1 = y; - y = x2; - x2 = y2; - y2 = y; - } - if (x1 > x2) - { - y = x1; - x1 = x2; - x2 = y; - y = y1; - y1 = y2; - y2 = y; - } - dx = x2 - x1; - dy = abs(y2 - y1); - e = 0.0f; - if (dx) - de = dy/(float)dx; - else - de = 0.0f; - y = y1; - sy = (y1= 0.5f) - { - y += sy; - e -= 1.0f; - } - } -} - -void Graphics::drawrect(int x, int y, int w, int h, int r, int g, int b, int a) -{ - int i; - w--; - h--; - for (i=0; i<=w; i++) - { - blendpixel(x+i, y, r, g, b, a); - blendpixel(x+i, y+h, r, g, b, a); - } - for (i=1; i YRES+MENUSIZE) h = (YRES+MENUSIZE)-y; //Adjust height to prevent drawing off the bottom - if(a >= 255) - for (j=0; jdraw_image(vid, 0, 0, VIDXRES, VIDYRES, 255); #endif } @@ -324,29 +333,29 @@ void Renderer::RenderZoom() #else int x, y, i, j; pixel pix; - pixel * img = g->vid; - g->drawrect(zoomWindowPosition.X-2, zoomWindowPosition.Y-2, zoomScopeSize*ZFACTOR+2, zoomScopeSize*ZFACTOR+2, 192, 192, 192, 255); - g->drawrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR, zoomScopeSize*ZFACTOR, 0, 0, 0, 255); - g->clearrect(zoomWindowPosition.X, zoomWindowPosition.Y, zoomScopeSize*ZFACTOR, zoomScopeSize*ZFACTOR); + pixel * img = vid; + drawrect(zoomWindowPosition.X-2, zoomWindowPosition.Y-2, zoomScopeSize*ZFACTOR+2, zoomScopeSize*ZFACTOR+2, 192, 192, 192, 255); + drawrect(zoomWindowPosition.X-1, zoomWindowPosition.Y-1, zoomScopeSize*ZFACTOR, zoomScopeSize*ZFACTOR, 0, 0, 0, 255); + clearrect(zoomWindowPosition.X, zoomWindowPosition.Y, zoomScopeSize*ZFACTOR, zoomScopeSize*ZFACTOR); for (j=0; jxor_pixel(zoomScopePosition.X+j, zoomScopePosition.Y-1); - g->xor_pixel(zoomScopePosition.X+j, zoomScopePosition.Y+zoomScopeSize); + xor_pixel(zoomScopePosition.X+j, zoomScopePosition.Y-1); + xor_pixel(zoomScopePosition.X+j, zoomScopePosition.Y+zoomScopeSize); } for (j=0; jxor_pixel(zoomScopePosition.X-1, zoomScopePosition.Y+j); - g->xor_pixel(zoomScopePosition.X+zoomScopeSize, zoomScopePosition.Y+j); + xor_pixel(zoomScopePosition.X-1, zoomScopePosition.Y+j); + xor_pixel(zoomScopePosition.X+zoomScopeSize, zoomScopePosition.Y+j); } } #endif @@ -362,8 +371,6 @@ void Renderer::DrawWalls() unsigned char (*bmap)[XRES/CELL] = sim->bmap; unsigned char (*emap)[XRES/CELL] = sim->emap; wall_type *wtypes = sim->wtypes; - pixel * vid = g->vid; - for (y=0; y>1)&1; iclearrect(x, y, w, h); - g->drawrect(x, y, w, h, 192, 192, 192, 255); + clearrect(x, y, w, h); + drawrect(x, y, w, h, 192, 192, 192, 255); //Displaying special information if (signs[i].text == "{p}") @@ -532,7 +539,7 @@ void Renderer::DrawSigns() if (signs[i].x>=0 && signs[i].x=0 && signs[i].ypv[signs[i].y/CELL][signs[i].x/CELL]; sprintf(buff, "Pressure: %3.2f", pressure); //...pressure - g->drawtext(x+3, y+3, buff, 255, 255, 255, 255); + drawtext(x+3, y+3, buff, 255, 255, 255, 255); } else if (signs[i].text == "{t}") { @@ -540,7 +547,7 @@ void Renderer::DrawSigns() sprintf(buff, "Temp: %4.2f", sim->parts[sim->pmap[signs[i].y][signs[i].x]>>8].temp-273.15); //...temperature else sprintf(buff, "Temp: 0.00"); //...temperature - g->drawtext(x+3, y+3, buff, 255, 255, 255, 255); + drawtext(x+3, y+3, buff, 255, 255, 255, 255); } else if (sregexp(signs[i].text.c_str(), "^{c:[0-9]*|.*}$")==0) { @@ -554,11 +561,11 @@ void Renderer::DrawSigns() buff[sldr - startm] = signs[i].text[sldr]; sldr++; } - g->drawtext(x+3, y+3, buff, 0, 191, 255, 255); + drawtext(x+3, y+3, buff, 0, 191, 255, 255); } else { - g->drawtext(x+3, y+3, signs[i].text, 255, 255, 255, 255); + drawtext(x+3, y+3, signs[i].text, 255, 255, 255, 255); } x = signs[i].x; @@ -574,7 +581,7 @@ void Renderer::DrawSigns() #else for (j=0; j<4; j++) { - g->blendpixel(x, y, 192, 192, 192, 255); + blendpixel(x, y, 192, 192, 192, 255); x+=dx; y+=dy; } @@ -601,8 +608,8 @@ void Renderer::render_gravlensing() int nx, ny, rx, ry, gx, gy, bx, by, co; int r, g, b; pixel t; - pixel *src = this->g->vid; - pixel *dst = this->g->vid; + pixel *src = vid; + pixel *dst = vid; for(nx = 0; nx < XRES; nx++) { for(ny = 0; ny < YRES; ny++) @@ -616,17 +623,17 @@ void Renderer::render_gravlensing() by = (int)(ny-sim->gravy[co]+0.5f); if(rx > 0 && rx < XRES && ry > 0 && ry < YRES && gx > 0 && gx < XRES && gy > 0 && gy < YRES && bx > 0 && bx < XRES && by > 0 && by < YRES) { - t = dst[ny*(XRES+BARSIZE)+nx]; - r = PIXR(src[ry*(XRES+BARSIZE)+rx]) + PIXR(t); - g = PIXG(src[gy*(XRES+BARSIZE)+gx]) + PIXG(t); - b = PIXB(src[by*(XRES+BARSIZE)+bx]) + PIXB(t); + t = dst[ny*(VIDXRES)+nx]; + r = PIXR(src[ry*(VIDXRES)+rx]) + PIXR(t); + g = PIXG(src[gy*(VIDXRES)+gx]) + PIXG(t); + b = PIXB(src[by*(VIDXRES)+bx]) + PIXB(t); if (r>255) r = 255; if (g>255) g = 255; if (b>255) b = 255; - dst[ny*(XRES+BARSIZE)+nx] = PIXRGB(r,g,b); + dst[ny*(VIDXRES)+nx] = PIXRGB(r,g,b); } } } @@ -646,7 +653,7 @@ void Renderer::render_fire() if (r || g || b) for (y=-CELL; y<2*CELL; y++) for (x=-CELL; x<2*CELL; x++) - this->g->addpixel(i*CELL+x, j*CELL+y, r, g, b, fire_alpha[y+CELL][x+CELL]); + addpixel(i*CELL+x, j*CELL+y, r, g, b, fire_alpha[y+CELL][x+CELL]); r *= 8; g *= 8; b *= 8; @@ -805,6 +812,8 @@ void Renderer::render_parts() if((sim->photons[ny][nx]&0xFF) && !(sim->elements[t].Properties & TYPE_ENERGY) && t!=PT_STKM && t!=PT_STKM2 && t!=PT_FIGH) continue; + if(nx >= XRES || nx < 0 || ny >= YRES || ny < 0) + continue; //Defaults pixel_mode = 0 | PMODE_FLAT; @@ -984,7 +993,7 @@ void Renderer::render_parts() /* if (mousex>(nx-3) && mousex<(nx+3) && mousey<(ny+3) && mousey>(ny-3)) //If mous is in the head { sprintf(buff, "%3d", sim->parts[i].life); //Show HP - g->drawtext(mousex-8-2*(sim->parts[i].life<100)-2*(sim->parts[i].life<10), mousey-12, buff, 255, 255, 255, 255); + drawtext(mousex-8-2*(sim->parts[i].life<100)-2*(sim->parts[i].life<10), mousey-12, buff, 255, 255, 255, 255); }*/ if (colour_mode!=COLOUR_HEAT) @@ -1045,7 +1054,7 @@ void Renderer::render_parts() glVertex2f(cplayer->legs[12], cplayer->legs[13]); glEnd(); #else - s = XRES+BARSIZE; + s = VIDXRES; if (t==PT_STKM2) { @@ -1070,23 +1079,23 @@ void Renderer::render_parts() //head if(t==PT_FIGH) { - g->draw_line(nx, ny+2, nx+2, ny, colr, colg, colb, s); - g->draw_line(nx+2, ny, nx, ny-2, colr, colg, colb, s); - g->draw_line(nx, ny-2, nx-2, ny, colr, colg, colb, s); - g->draw_line(nx-2, ny, nx, ny+2, colr, colg, colb, s); + draw_line(nx, ny+2, nx+2, ny, colr, colg, colb, s); + draw_line(nx+2, ny, nx, ny-2, colr, colg, colb, s); + draw_line(nx, ny-2, nx-2, ny, colr, colg, colb, s); + draw_line(nx-2, ny, nx, ny+2, colr, colg, colb, s); } else { - g->draw_line(nx-2, ny+2, nx+2, ny+2, colr, colg, colb, s); - g->draw_line(nx-2, ny-2, nx+2, ny-2, colr, colg, colb, s); - g->draw_line(nx-2, ny-2, nx-2, ny+2, colr, colg, colb, s); - g->draw_line(nx+2, ny-2, nx+2, ny+2, colr, colg, colb, s); + draw_line(nx-2, ny+2, nx+2, ny+2, colr, colg, colb, s); + draw_line(nx-2, ny-2, nx+2, ny-2, colr, colg, colb, s); + draw_line(nx-2, ny-2, nx-2, ny+2, colr, colg, colb, s); + draw_line(nx+2, ny-2, nx+2, ny+2, colr, colg, colb, s); } //legs - g->draw_line(nx, ny+3, cplayer->legs[0], cplayer->legs[1], legr, legg, legb, s); - g->draw_line(cplayer->legs[0], cplayer->legs[1], cplayer->legs[4], cplayer->legs[5], legr, legg, legb, s); - g->draw_line(nx, ny+3, cplayer->legs[8], cplayer->legs[9], legr, legg, legb, s); - g->draw_line(cplayer->legs[8], cplayer->legs[9], cplayer->legs[12], cplayer->legs[13], legr, legg, legb, s); + draw_line(nx, ny+3, cplayer->legs[0], cplayer->legs[1], legr, legg, legb, s); + draw_line(cplayer->legs[0], cplayer->legs[1], cplayer->legs[4], cplayer->legs[5], legr, legg, legb, s); + draw_line(nx, ny+3, cplayer->legs[8], cplayer->legs[9], legr, legg, legb, s); + draw_line(cplayer->legs[8], cplayer->legs[9], cplayer->legs[12], cplayer->legs[13], legr, legg, legb, s); #endif } if(pixel_mode & PMODE_FLAT) @@ -1100,7 +1109,7 @@ void Renderer::render_parts() flatC[cflatC++] = 1.0f; cflat++; #else - g->vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(colr,colg,colb); + vid[ny*(VIDXRES)+nx] = PIXRGB(colr,colg,colb); #endif } if(pixel_mode & PMODE_BLEND) @@ -1114,7 +1123,7 @@ void Renderer::render_parts() flatC[cflatC++] = ((float)cola)/255.0f; cflat++; #else - g->blendpixel(nx, ny, colr, colg, colb, cola); + blendpixel(nx, ny, colr, colg, colb, cola); #endif } if(pixel_mode & PMODE_ADD) @@ -1128,7 +1137,7 @@ void Renderer::render_parts() addC[caddC++] = ((float)cola)/255.0f; cadd++; #else - g->addpixel(nx, ny, colr, colg, colb, cola); + addpixel(nx, ny, colr, colg, colb, cola); #endif } if(pixel_mode & PMODE_BLOB) @@ -1142,17 +1151,17 @@ void Renderer::render_parts() blobC[cblobC++] = 1.0f; cblob++; #else - g->vid[ny*(XRES+BARSIZE)+nx] = PIXRGB(colr,colg,colb); + vid[ny*(VIDXRES)+nx] = PIXRGB(colr,colg,colb); - g->blendpixel(nx+1, ny, colr, colg, colb, 223); - g->blendpixel(nx-1, ny, colr, colg, colb, 223); - g->blendpixel(nx, ny+1, colr, colg, colb, 223); - g->blendpixel(nx, ny-1, colr, colg, colb, 223); + blendpixel(nx+1, ny, colr, colg, colb, 223); + blendpixel(nx-1, ny, colr, colg, colb, 223); + blendpixel(nx, ny+1, colr, colg, colb, 223); + blendpixel(nx, ny-1, colr, colg, colb, 223); - g->blendpixel(nx+1, ny-1, colr, colg, colb, 112); - g->blendpixel(nx-1, ny-1, colr, colg, colb, 112); - g->blendpixel(nx+1, ny+1, colr, colg, colb, 112); - g->blendpixel(nx-1, ny+1, colr, colg, colb, 112); + blendpixel(nx+1, ny-1, colr, colg, colb, 112); + blendpixel(nx-1, ny-1, colr, colg, colb, 112); + blendpixel(nx+1, ny+1, colr, colg, colb, 112); + blendpixel(nx-1, ny+1, colr, colg, colb, 112); #endif } if(pixel_mode & PMODE_GLOW) @@ -1167,24 +1176,24 @@ void Renderer::render_parts() glowC[cglowC++] = 1.0f; cglow++; #else - g->addpixel(nx, ny, colr, colg, colb, (192*cola)/255); - g->addpixel(nx+1, ny, colr, colg, colb, (96*cola)/255); - g->addpixel(nx-1, ny, colr, colg, colb, (96*cola)/255); - g->addpixel(nx, ny+1, colr, colg, colb, (96*cola)/255); - g->addpixel(nx, ny-1, colr, colg, colb, (96*cola)/255); + addpixel(nx, ny, colr, colg, colb, (192*cola)/255); + addpixel(nx+1, ny, colr, colg, colb, (96*cola)/255); + addpixel(nx-1, ny, colr, colg, colb, (96*cola)/255); + addpixel(nx, ny+1, colr, colg, colb, (96*cola)/255); + addpixel(nx, ny-1, colr, colg, colb, (96*cola)/255); for (x = 1; x < 6; x++) { - g->addpixel(nx, ny-x, colr, colg, colb, cola1); - g->addpixel(nx, ny+x, colr, colg, colb, cola1); - g->addpixel(nx-x, ny, colr, colg, colb, cola1); - g->addpixel(nx+x, ny, colr, colg, colb, cola1); + addpixel(nx, ny-x, colr, colg, colb, cola1); + addpixel(nx, ny+x, colr, colg, colb, cola1); + addpixel(nx-x, ny, colr, colg, colb, cola1); + addpixel(nx+x, ny, colr, colg, colb, cola1); for (y = 1; y < 6; y++) { if(x + y > 7) continue; - g->addpixel(nx+x, ny-y, colr, colg, colb, cola1); - g->addpixel(nx-x, ny+y, colr, colg, colb, cola1); - g->addpixel(nx+x, ny+y, colr, colg, colb, cola1); - g->addpixel(nx-x, ny-y, colr, colg, colb, cola1); + addpixel(nx+x, ny-y, colr, colg, colb, cola1); + addpixel(nx-x, ny+y, colr, colg, colb, cola1); + addpixel(nx+x, ny+y, colr, colg, colb, cola1); + addpixel(nx-x, ny-y, colr, colg, colb, cola1); } } #endif @@ -1205,11 +1214,11 @@ void Renderer::render_parts() for (y=-3; y<4; y++) { if (abs(x)+abs(y) <2 && !(abs(x)==2||abs(y)==2)) - g->blendpixel(x+nx, y+ny, colr, colg, colb, 30); + blendpixel(x+nx, y+ny, colr, colg, colb, 30); if (abs(x)+abs(y) <=3 && abs(x)+abs(y)) - g->blendpixel(x+nx, y+ny, colr, colg, colb, 20); + blendpixel(x+nx, y+ny, colr, colg, colb, 20); if (abs(x)+abs(y) == 2) - g->blendpixel(x+nx, y+ny, colr, colg, colb, 10); + blendpixel(x+nx, y+ny, colr, colg, colb, 10); } } #endif @@ -1269,11 +1278,11 @@ void Renderer::render_parts() #else gradv = 4*sim->parts[i].life + flicker; for (x = 0; gradv>0.5; x++) { - g->addpixel(nx+x, ny, colr, colg, colb, gradv); - g->addpixel(nx-x, ny, colr, colg, colb, gradv); + addpixel(nx+x, ny, colr, colg, colb, gradv); + addpixel(nx-x, ny, colr, colg, colb, gradv); - g->addpixel(nx, ny+x, colr, colg, colb, gradv); - g->addpixel(nx, ny-x, colr, colg, colb, gradv); + addpixel(nx, ny+x, colr, colg, colb, gradv); + addpixel(nx, ny-x, colr, colg, colb, gradv); gradv = gradv/1.5f; } #endif @@ -1332,21 +1341,21 @@ void Renderer::render_parts() cline++; #else gradv = flicker + fabs(parts[i].vx)*17 + fabs(sim->parts[i].vy)*17; - g->blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); - g->blendpixel(nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - g->blendpixel(nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - g->blendpixel(nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - g->blendpixel(nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); + blendpixel(nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); if (gradv>255) gradv=255; - g->blendpixel(nx+1, ny-1, colr, colg, colb, gradv); - g->blendpixel(nx-1, ny-1, colr, colg, colb, gradv); - g->blendpixel(nx+1, ny+1, colr, colg, colb, gradv); - g->blendpixel(nx-1, ny+1, colr, colg, colb, gradv); + blendpixel(nx+1, ny-1, colr, colg, colb, gradv); + blendpixel(nx-1, ny-1, colr, colg, colb, gradv); + blendpixel(nx+1, ny+1, colr, colg, colb, gradv); + blendpixel(nx-1, ny+1, colr, colg, colb, gradv); for (x = 1; gradv>0.5; x++) { - g->addpixel(nx+x, ny, colr, colg, colb, gradv); - g->addpixel(nx-x, ny, colr, colg, colb, gradv); - g->addpixel(nx, ny+x, colr, colg, colb, gradv); - g->addpixel(nx, ny-x, colr, colg, colb, gradv); + addpixel(nx+x, ny, colr, colg, colb, gradv); + addpixel(nx-x, ny, colr, colg, colb, gradv); + addpixel(nx, ny+x, colr, colg, colb, gradv); + addpixel(nx, ny-x, colr, colg, colb, gradv); gradv = gradv/1.2f; } #endif @@ -1405,21 +1414,21 @@ void Renderer::render_parts() cline++; #else gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17; - g->blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); - g->blendpixel(nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - g->blendpixel(nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - g->blendpixel(nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); - g->blendpixel(nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); + blendpixel(nx+1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx-1, ny, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny+1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); + blendpixel(nx, ny-1, colr, colg, colb, (gradv*2)>255?255:(gradv*2) ); if (gradv>255) gradv=255; - g->blendpixel(nx+1, ny-1, colr, colg, colb, gradv); - g->blendpixel(nx-1, ny-1, colr, colg, colb, gradv); - g->blendpixel(nx+1, ny+1, colr, colg, colb, gradv); - g->blendpixel(nx-1, ny+1, colr, colg, colb, gradv); + blendpixel(nx+1, ny-1, colr, colg, colb, gradv); + blendpixel(nx-1, ny-1, colr, colg, colb, gradv); + blendpixel(nx+1, ny+1, colr, colg, colb, gradv); + blendpixel(nx-1, ny+1, colr, colg, colb, gradv); for (x = 1; gradv>0.5; x++) { - g->addpixel(nx+x, ny, colr, colg, colb, gradv); - g->addpixel(nx-x, ny, colr, colg, colb, gradv); - g->addpixel(nx, ny+x, colr, colg, colb, gradv); - g->addpixel(nx, ny-x, colr, colg, colb, gradv); + addpixel(nx+x, ny, colr, colg, colb, gradv); + addpixel(nx-x, ny, colr, colg, colb, gradv); + addpixel(nx, ny+x, colr, colg, colb, gradv); + addpixel(nx, ny-x, colr, colg, colb, gradv); gradv = gradv/1.01f; } #endif @@ -1439,7 +1448,7 @@ void Renderer::render_parts() nxo = ddist*cos(drad); nyo = ddist*sin(drad); if (ny+nyo>0 && ny+nyo0 && nx+nxoaddpixel(nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]); + addpixel(nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]); } } if (pixel_mode & EFFECT_GRAVOUT) @@ -1457,7 +1466,7 @@ void Renderer::render_parts() nxo = ddist*cos(drad); nyo = ddist*sin(drad); if (ny+nyo>0 && ny+nyo0 && nx+nxoaddpixel(nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]); + addpixel(nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]); } } //Fire effects @@ -1730,7 +1739,7 @@ void Renderer::draw_other() // EMP effect for (j=0; jg->blendpixel(i, j, r, g, b, a); + blendpixel(i, j, r, g, b, a); } #endif } @@ -1755,7 +1764,7 @@ void Renderer::draw_grav() { nx -= sim->gravx[ca]*0.5f; ny -= sim->gravy[ca]*0.5f; - g->addpixel((int)(nx+0.5f), (int)(ny+0.5f), 255, 255, 255, (int)(dist*20.0f)); + addpixel((int)(nx+0.5f), (int)(ny+0.5f), 255, 255, 255, (int)(dist*20.0f)); } } } @@ -1831,7 +1840,7 @@ void Renderer::draw_air() } for (j=0; jvid[(x*CELL+i) + (y*CELL+j)*(XRES+BARSIZE)] = c; + vid[(x*CELL+i) + (y*CELL+j)*(VIDXRES)] = c; } #else int sdl_scale = 1; @@ -1905,9 +1914,9 @@ void Renderer::draw_grav_zones() for (j=0; jblendpixel(x*CELL+i, y*CELL+j, 255, 200, 0, 120); + blendpixel(x*CELL+i, y*CELL+j, 255, 200, 0, 120); else - g->blendpixel(x*CELL+i, y*CELL+j, 32, 32, 32, 120); + blendpixel(x*CELL+i, y*CELL+j, 32, 32, 32, 120); } } } @@ -1915,15 +1924,15 @@ void Renderer::draw_grav_zones() void Renderer::drawblob(int x, int y, unsigned char cr, unsigned char cg, unsigned char cb) { - g->blendpixel(x+1, y, cr, cg, cb, 112); - g->blendpixel(x-1, y, cr, cg, cb, 112); - g->blendpixel(x, y+1, cr, cg, cb, 112); - g->blendpixel(x, y-1, cr, cg, cb, 112); + blendpixel(x+1, y, cr, cg, cb, 112); + blendpixel(x-1, y, cr, cg, cb, 112); + blendpixel(x, y+1, cr, cg, cb, 112); + blendpixel(x, y-1, cr, cg, cb, 112); - g->blendpixel(x+1, y-1, cr, cg, cb, 64); - g->blendpixel(x-1, y-1, cr, cg, cb, 64); - g->blendpixel(x+1, y+1, cr, cg, cb, 64); - g->blendpixel(x-1, y+1, cr, cg, cb, 64); + blendpixel(x+1, y-1, cr, cg, cb, 64); + blendpixel(x-1, y-1, cr, cg, cb, 64); + blendpixel(x+1, y+1, cr, cg, cb, 64); + blendpixel(x-1, y+1, cr, cg, cb, 64); } Renderer::Renderer(Graphics * g, Simulation * sim): @@ -1938,6 +1947,13 @@ Renderer::Renderer(Graphics * g, Simulation * sim): { this->g = g; this->sim = sim; +#if !defined(OGLR) +#if defined(OGLI) + vid = new pixel[VIDXRES*VIDYRES]; +#else + vid = vid; +#endif +#endif memset(fire_r, 0, sizeof(fire_r)); memset(fire_g, 0, sizeof(fire_g)); @@ -2201,3 +2217,7 @@ Renderer::~Renderer() free(plasma_data); } +#define PIXELMETHODS_CLASS Renderer +#include "PixelMethods.inc" +#undef PIXELMETHODS_CLASS + diff --git a/src/Renderer.h b/src/Renderer.h index 8ad6a58c3..88e379a55 100644 --- a/src/Renderer.h +++ b/src/Renderer.h @@ -75,6 +75,30 @@ public: void checkShader(GLuint shader, char * shname); void checkProgram(GLuint program, char * progname); void loadShaders(); +#else + pixel * vid; + void blendpixel(int x, int y, int r, int g, int b, int a); + void addpixel(int x, int y, int r, int g, int b, int a); + + void draw_icon(int x, int y, Icon icon); + + int drawtext(int x, int y, const char *s, int r, int g, int b, int a); + int drawtext(int x, int y, std::string s, int r, int g, int b, int a); + int drawchar(int x, int y, int c, int r, int g, int b, int a); + int addchar(int x, int y, int c, int r, int g, int b, int a); + + void xor_pixel(int x, int y); + void xor_line(int x, int y, int x2, int y2); + void xor_rect(int x, int y, int width, int height); + void xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h); + + void draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a); + void drawrect(int x, int y, int width, int height, int r, int g, int b, int a); + void fillrect(int x, int y, int width, int height, int r, int g, int b, int a); + void clearrect(int x, int y, int width, int height); + void gradientrect(int x, int y, int width, int height, int r, int g, int b, int a, int r2, int g2, int b2, int a2); + + void draw_image(pixel *img, int x, int y, int w, int h, int a); #endif void drawblob(int x, int y, unsigned char cr, unsigned char cg, unsigned char cb); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index faacad4b6..5593d4b3c 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -870,7 +870,7 @@ void GameView::DoMouseMove(int x, int y, int dx, int dy) } else { - scrollBar->Position.X = 0; + scrollBar->Position.X = 0; } scrollBar->Size.X=scrollSize; } diff --git a/src/interface/Engine.cpp b/src/interface/Engine.cpp index 76832b67c..2526efb4d 100644 --- a/src/interface/Engine.cpp +++ b/src/interface/Engine.cpp @@ -76,7 +76,7 @@ void Engine::ShowWindow(Window * window) } lastBuffer = (pixel*)malloc((width_ * height_) * PIXELSIZE); -#ifndef OGLR +#ifndef OGLI memcpy(lastBuffer, g->vid, (width_ * height_) * PIXELSIZE); #endif @@ -171,7 +171,7 @@ void Engine::Draw() if(lastBuffer && !(state_->Position.X == 0 && state_->Position.Y == 0 && state_->Size.X == width_ && state_->Size.Y == height_)) { g->Clear(); -#ifndef OGLR +#ifndef OGLI memcpy(g->vid, lastBuffer, (width_ * height_) * PIXELSIZE); #endif } diff --git a/src/interface/Slider.cpp b/src/interface/Slider.cpp index 3430ca1bf..3b188b4e5 100644 --- a/src/interface/Slider.cpp +++ b/src/interface/Slider.cpp @@ -104,7 +104,7 @@ void Slider::Draw(const Point& screenPos) if(bgGradient) { -#ifndef OGLR +#ifndef OGLI for (int j = 3; j < Size.Y-6; j++) for (int i = 3; i < Size.X-6; i++) g->blendpixel(screenPos.X+i+2, screenPos.Y+j+2, bgGradient[(i-3)*3], bgGradient[(i-3)*3+1], bgGradient[(i-3)*3+2], 255);