Option to use OpenGL JUST for the interface
This commit is contained in:
parent
4cf42e786b
commit
f5547f267b
@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#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
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "Graphics.h"
|
||||
#include "font.h"
|
||||
|
||||
#ifdef OGLR
|
||||
#ifdef OGLI
|
||||
|
||||
Graphics::Graphics():
|
||||
sdl_scale(1)
|
||||
|
332
src/PixelMethods.inc
Normal file
332
src/PixelMethods.inc
Normal file
@ -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<FONT_H; j++)
|
||||
for (i=0; i<w; i++)
|
||||
{
|
||||
if (!bn)
|
||||
{
|
||||
ba = *(rp++);
|
||||
bn = 8;
|
||||
}
|
||||
blendpixel(x+i, y+j, r, g, b, ((ba&3)*a)/3);
|
||||
ba >>= 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<FONT_H; j++)
|
||||
for (i=0; i<w; i++)
|
||||
{
|
||||
if (!bn)
|
||||
{
|
||||
ba = *(rp++);
|
||||
bn = 8;
|
||||
}
|
||||
{
|
||||
addpixel(x+i, y+j, r, g, b, ((ba&3)*a)/3);
|
||||
}
|
||||
ba >>= 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<y2) ? 1 : -1;
|
||||
for (x=x1; x<=x2; x++)
|
||||
{
|
||||
if (cp)
|
||||
xor_pixel(y, x);
|
||||
else
|
||||
xor_pixel(x, y);
|
||||
e += de;
|
||||
if (e >= 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; i<w; i+=2)
|
||||
{
|
||||
xor_pixel(x+i, y);
|
||||
xor_pixel(x+i, y+h-1);
|
||||
}
|
||||
for (i=2; i<h; i+=2)
|
||||
{
|
||||
xor_pixel(x, y+i);
|
||||
xor_pixel(x+w-1, y+i);
|
||||
}
|
||||
}
|
||||
|
||||
void PIXELMETHODS_CLASS::xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h)
|
||||
{
|
||||
for(int x1 = 0; x1 < w; x1++)
|
||||
{
|
||||
for(int y1 = 0; y1 < h; y1++)
|
||||
{
|
||||
if(bitmap[y1*w+x1])
|
||||
xor_pixel(x+x1, y+y1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PIXELMETHODS_CLASS::draw_line(int x1, int y1, int x2, int y2, int r, int g, int b, int a)
|
||||
{
|
||||
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<y2) ? 1 : -1;
|
||||
for (x=x1; x<=x2; x++)
|
||||
{
|
||||
if (cp)
|
||||
blendpixel(y, x, r, g, b, a);
|
||||
else
|
||||
blendpixel(x, y, r, g, b, a);
|
||||
e += de;
|
||||
if (e >= 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<h; i++)
|
||||
{
|
||||
blendpixel(x, y+i, r, g, b, a);
|
||||
blendpixel(x+w, y+i, r, g, b, a);
|
||||
}
|
||||
}
|
||||
|
||||
void PIXELMETHODS_CLASS::fillrect(int x, int y, int w, int h, int r, int g, int b, int a)
|
||||
{
|
||||
int i,j;
|
||||
for (j=0; j<h; j++)
|
||||
for (i=0; i<w; i++)
|
||||
blendpixel(x+i, y+j, r, g, b, a);
|
||||
}
|
||||
|
||||
void PIXELMETHODS_CLASS::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 PIXELMETHODS_CLASS::clearrect(int x, int y, int w, int h)
|
||||
{
|
||||
int i;
|
||||
for (i=1; i<h; i++)
|
||||
memset(vid+(x+1+(VIDXRES)*(y+i)), 0, PIXELSIZE*(w-1));
|
||||
}
|
||||
|
||||
void PIXELMETHODS_CLASS::draw_image(pixel *img, int x, int y, int w, int h, int a)
|
||||
{
|
||||
int i, j, r, g, b;
|
||||
if (!img) return;
|
||||
if(y + h > VIDYRES) h = (VIDYRES)-y; //Adjust height to prevent drawing off the bottom
|
||||
if(a >= 255)
|
||||
for (j=0; j<h; j++)
|
||||
for (i=0; i<w; i++)
|
||||
{
|
||||
vid[(y+j)*(VIDXRES)+(x+i)] = *img;
|
||||
img++;
|
||||
}
|
||||
else
|
||||
for (j=0; j<h; j++)
|
||||
for (i=0; i<w; i++)
|
||||
{
|
||||
r = PIXR(*img);
|
||||
g = PIXG(*img);
|
||||
b = PIXB(*img);
|
||||
blendpixel(x+i, y+j, r, g, b, a);
|
||||
img++;
|
||||
}
|
||||
}
|
17
src/PixelMethodsDef.inc
Normal file
17
src/PixelMethodsDef.inc
Normal file
@ -0,0 +1,17 @@
|
||||
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);
|
@ -38,7 +38,7 @@ extern "C" IMAGE_DOS_HEADER __ImageBase;
|
||||
|
||||
SDL_Surface * sdl_scrn;
|
||||
|
||||
#ifdef OGLR
|
||||
#ifdef OGLI
|
||||
void blit()
|
||||
{
|
||||
SDL_GL_SwapBuffers();
|
||||
@ -110,13 +110,13 @@ SDL_Surface * SDLOpen()
|
||||
SDL_WM_SetCaption("The Powder Toy", "Powder Toy");
|
||||
//SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
|
||||
atexit(SDL_Quit);
|
||||
#ifndef OGLR
|
||||
#ifndef OGLI
|
||||
surface = SDL_SetVideoMode(XRES + BARSIZE, YRES + MENUSIZE, 32, SDL_SWSURFACE);
|
||||
#else
|
||||
surface = SDL_SetVideoMode(XRES + BARSIZE, YRES + MENUSIZE, 32, SDL_OPENGL);
|
||||
#endif
|
||||
|
||||
#if defined(OGLR)
|
||||
#if defined(OGLI)
|
||||
int status = glewInit();
|
||||
if(status != GLEW_OK)
|
||||
{
|
||||
@ -135,7 +135,7 @@ int main(int argc, char * argv[])
|
||||
float fps = 0, delta = 1.0f;
|
||||
|
||||
sdl_scrn = SDLOpen();
|
||||
#ifdef OGLR
|
||||
#ifdef OGLI
|
||||
SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
|
||||
#endif
|
||||
|
||||
@ -195,14 +195,14 @@ int main(int argc, char * argv[])
|
||||
engine->Tick();
|
||||
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);
|
||||
|
@ -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<FONT_H; j++)
|
||||
for (i=0; i<w; i++)
|
||||
{
|
||||
if (!bn)
|
||||
{
|
||||
ba = *(rp++);
|
||||
bn = 8;
|
||||
}
|
||||
blendpixel(x+i, y+j, r, g, b, ((ba&3)*a)/3);
|
||||
ba >>= 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<FONT_H; j++)
|
||||
for (i=0; i<w; i++)
|
||||
{
|
||||
if (!bn)
|
||||
{
|
||||
ba = *(rp++);
|
||||
bn = 8;
|
||||
}
|
||||
{
|
||||
addpixel(x+i, y+j, r, g, b, ((ba&3)*a)/3);
|
||||
}
|
||||
ba >>= 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<y2) ? 1 : -1;
|
||||
for (x=x1; x<=x2; x++)
|
||||
{
|
||||
if (cp)
|
||||
xor_pixel(y, x);
|
||||
else
|
||||
xor_pixel(x, y);
|
||||
e += de;
|
||||
if (e >= 0.5f)
|
||||
{
|
||||
y += sy;
|
||||
e -= 1.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::xor_rect(int x, int y, int w, int h)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<w; i+=2)
|
||||
{
|
||||
xor_pixel(x+i, y);
|
||||
xor_pixel(x+i, y+h-1);
|
||||
}
|
||||
for (i=2; i<h; i+=2)
|
||||
{
|
||||
xor_pixel(x, y+i);
|
||||
xor_pixel(x+w-1, y+i);
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h)
|
||||
{
|
||||
for(int x1 = 0; x1 < w; x1++)
|
||||
{
|
||||
for(int y1 = 0; y1 < h; y1++)
|
||||
{
|
||||
if(bitmap[y1*w+x1])
|
||||
xor_pixel(x+x1, y+y1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::draw_line(int x1, int y1, int x2, int y2, int r, int g, int b, int a)
|
||||
{
|
||||
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<y2) ? 1 : -1;
|
||||
for (x=x1; x<=x2; x++)
|
||||
{
|
||||
if (cp)
|
||||
blendpixel(y, x, r, g, b, a);
|
||||
else
|
||||
blendpixel(x, y, r, g, b, a);
|
||||
e += de;
|
||||
if (e >= 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<h; i++)
|
||||
{
|
||||
blendpixel(x, y+i, r, g, b, a);
|
||||
blendpixel(x+w, y+i, r, g, b, a);
|
||||
}
|
||||
}
|
||||
|
||||
void Graphics::fillrect(int x, int y, int w, int h, int r, int g, int b, int a)
|
||||
{
|
||||
int i,j;
|
||||
for (j=0; j<h; j++)
|
||||
for (i=0; i<w; i++)
|
||||
blendpixel(x+i, y+j, r, g, b, a);
|
||||
}
|
||||
|
||||
void Graphics::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 Graphics::clearrect(int x, int y, int w, int h)
|
||||
{
|
||||
int i;
|
||||
for (i=1; i<h; i++)
|
||||
memset(vid+(x+1+(XRES+BARSIZE)*(y+i)), 0, PIXELSIZE*(w-1));
|
||||
}
|
||||
|
||||
void Graphics::draw_image(pixel *img, int x, int y, int w, int h, int a)
|
||||
{
|
||||
int i, j, r, g, b;
|
||||
if (!img) return;
|
||||
if(y + h > YRES+MENUSIZE) h = (YRES+MENUSIZE)-y; //Adjust height to prevent drawing off the bottom
|
||||
if(a >= 255)
|
||||
for (j=0; j<h; j++)
|
||||
for (i=0; i<w; i++)
|
||||
{
|
||||
vid[(y+j)*(XRES+BARSIZE)+(x+i)] = *img;
|
||||
img++;
|
||||
}
|
||||
else
|
||||
for (j=0; j<h; j++)
|
||||
for (i=0; i<w; i++)
|
||||
{
|
||||
r = PIXR(*img);
|
||||
g = PIXG(*img);
|
||||
b = PIXB(*img);
|
||||
blendpixel(x+i, y+j, r, g, b, a);
|
||||
img++;
|
||||
}
|
||||
}
|
||||
#define VIDXRES XRES+BARSIZE
|
||||
#define VIDYRES YRES+MENUSIZE
|
||||
#define PIXELMOETHODS_CLASS Graphics
|
||||
#include "PixelMethods.inc"
|
||||
#undef VIDYRES
|
||||
#undef VIDXRES
|
||||
#undef PIXELMETHODS_CLASS
|
||||
|
||||
#endif
|
||||
|
274
src/Renderer.cpp
274
src/Renderer.cpp
@ -23,6 +23,13 @@ extern "C"
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef OGLI
|
||||
#define VIDXRES VIDXRES
|
||||
#define VIDYRES YRES+MENUSIZE
|
||||
#else
|
||||
#define VIDXRES XRES
|
||||
#define VIDYRES YRES
|
||||
#endif
|
||||
|
||||
void Renderer::clearScreen(float alpha)
|
||||
{
|
||||
@ -228,6 +235,8 @@ void Renderer::FinaliseParts()
|
||||
}
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
#else
|
||||
g->draw_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; j<zoomScopeSize; j++)
|
||||
for (i=0; i<zoomScopeSize; i++)
|
||||
{
|
||||
pix = img[(j+zoomScopePosition.Y)*(XRES+BARSIZE)+(i+zoomScopePosition.X)];
|
||||
pix = img[(j+zoomScopePosition.Y)*(VIDXRES)+(i+zoomScopePosition.X)];
|
||||
for (y=0; y<ZFACTOR-1; y++)
|
||||
for (x=0; x<ZFACTOR-1; x++)
|
||||
img[(j*ZFACTOR+y+zoomWindowPosition.Y)*(XRES+BARSIZE)+(i*ZFACTOR+x+zoomWindowPosition.X)] = pix;
|
||||
img[(j*ZFACTOR+y+zoomWindowPosition.Y)*(VIDXRES)+(i*ZFACTOR+x+zoomWindowPosition.X)] = pix;
|
||||
}
|
||||
if (zoomEnabled)
|
||||
{
|
||||
for (j=-1; j<=zoomScopeSize; j++)
|
||||
{
|
||||
g->xor_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; j<zoomScopeSize; j++)
|
||||
{
|
||||
g->xor_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<YRES/CELL; y++)
|
||||
for (x=0; x<XRES/CELL; x++)
|
||||
if (bmap[y][x])
|
||||
@ -379,30 +386,30 @@ void Renderer::DrawWalls()
|
||||
{
|
||||
for (j=0; j<CELL; j+=2)
|
||||
for (i=(j>>1)&1; i<CELL; i+=2)
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc;
|
||||
}
|
||||
else if (wtypes[wt].drawstyle==2)
|
||||
{
|
||||
for (j=0; j<CELL; j+=2)
|
||||
for (i=0; i<CELL; i+=2)
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc;
|
||||
}
|
||||
else if (wtypes[wt].drawstyle==3)
|
||||
{
|
||||
for (j=0; j<CELL; j++)
|
||||
for (i=0; i<CELL; i++)
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc;
|
||||
}
|
||||
else if (wtypes[wt].drawstyle==4)
|
||||
{
|
||||
for (j=0; j<CELL; j++)
|
||||
for (i=0; i<CELL; i++)
|
||||
if(i == j)
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc;
|
||||
else if (i == j+1 || (i == 0 && j == CELL-1))
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = gc;
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = gc;
|
||||
else
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x202020);
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = PIXPACK(0x202020);
|
||||
}
|
||||
|
||||
// special rendering for some walls
|
||||
@ -413,14 +420,14 @@ void Renderer::DrawWalls()
|
||||
for (j=0; j<CELL; j++)
|
||||
for (i=0; i<CELL; i++)
|
||||
if (i&j&1)
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j=0; j<CELL; j++)
|
||||
for (i=0; i<CELL; i++)
|
||||
if (!(i&j&1))
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc;
|
||||
}
|
||||
}
|
||||
else if (wt==WL_WALLELEC)
|
||||
@ -429,9 +436,9 @@ void Renderer::DrawWalls()
|
||||
for (i=0; i<CELL; i++)
|
||||
{
|
||||
if (!((y*CELL+j)%2) && !((x*CELL+i)%2))
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = pc;
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = pc;
|
||||
else
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x808080);
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = PIXPACK(0x808080);
|
||||
}
|
||||
}
|
||||
else if (wt==WL_EHOLE)
|
||||
@ -440,16 +447,16 @@ void Renderer::DrawWalls()
|
||||
{
|
||||
for (j=0; j<CELL; j++)
|
||||
for (i=0; i<CELL; i++)
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x242424);
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = PIXPACK(0x242424);
|
||||
for (j=0; j<CELL; j+=2)
|
||||
for (i=0; i<CELL; i+=2)
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x000000);
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = PIXPACK(0x000000);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (j=0; j<CELL; j+=2)
|
||||
for (i=0; i<CELL; i+=2)
|
||||
vid[(y*CELL+j)*(XRES+BARSIZE)+(x*CELL+i)] = PIXPACK(0x242424);
|
||||
vid[(y*CELL+j)*(VIDXRES)+(x*CELL+i)] = PIXPACK(0x242424);
|
||||
}
|
||||
}
|
||||
if (wtypes[wt].eglow && emap[y][x])
|
||||
@ -522,8 +529,8 @@ void Renderer::DrawSigns()
|
||||
{
|
||||
char buff[256]; //Buffer
|
||||
get_sign_pos(i, &x, &y, &w, &h);
|
||||
g->clearrect(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<XRES && signs[i].y>=0 && signs[i].y<YRES)
|
||||
pressure = sim->pv[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+nyo<YRES && nx+nxo>0 && nx+nxo<XRES)
|
||||
g->addpixel(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+nyo<YRES && nx+nxo>0 && nx+nxo<XRES)
|
||||
g->addpixel(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; j<YRES; j++)
|
||||
for (i=0; i<XRES; i++)
|
||||
{
|
||||
this->g->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; j<CELL; j++)//draws the colors
|
||||
for (i=0; i<CELL; i++)
|
||||
g->vid[(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; j<CELL; j++)//draws the colors
|
||||
for (i=0; i<CELL; i++)
|
||||
if(i == j)
|
||||
g->blendpixel(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
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user