xor_bitmap drawing for renderer

This commit is contained in:
Simon Robertshaw 2012-08-15 16:25:13 +01:00
parent 2f0e67433c
commit 98445721fd
3 changed files with 85 additions and 30 deletions

View File

@ -228,16 +228,16 @@ void PIXELMETHODS_CLASS::xor_rect(int x, int y, int width, int height)
void PIXELMETHODS_CLASS::xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h) void PIXELMETHODS_CLASS::xor_bitmap(unsigned char * bitmap, int x, int y, int w, int h)
{ {
/* Rewriting until better method can be found */
//glEnable(GL_COLOR_LOGIC_OP); //glEnable(GL_COLOR_LOGIC_OP);
//glLogicOp(GL_XOR); //glLogicOp(GL_XOR);
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textTexture); glBindTexture(GL_TEXTURE_2D, textTexture);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap); glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, bitmap);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2d(0, 0); glTexCoord2d(0, 0);
@ -254,22 +254,6 @@ void PIXELMETHODS_CLASS::xor_bitmap(unsigned char * bitmap, int x, int y, int w,
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
//glDisable(GL_COLOR_LOGIC_OP); //glDisable(GL_COLOR_LOGIC_OP);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
/*float old_size;
glGetFloatv(GL_POINT_SIZE,&old_size);
glPointSize(1.0);
glBegin(GL_POINTS);
glColor4f(1.0f,1.0f,1.0f,1.0f);
for(int i =0; i < w*h; i++)
{
if(bitmap[i]==255)
{
glVertex2f(x+i%w,y+i/w);
}
}
glEnd();
glPointSize(old_size);*/
} }
void PIXELMETHODS_CLASS::draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a) void PIXELMETHODS_CLASS::draw_line(int x, int y, int x2, int y2, int r, int g, int b, int a)

View File

@ -34,7 +34,20 @@ extern "C"
void Renderer::RenderBegin() void Renderer::RenderBegin()
{ {
#ifndef OGLR #ifdef OGLI
#ifdef OGLR
draw_air();
draw_grav();
render_parts();
render_fire();
DrawWalls();
draw_grav_zones();
DrawSigns();
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
glTranslated(0, MENUSIZE, 0);
#else
if(display_mode & DISPLAY_PERS) if(display_mode & DISPLAY_PERS)
{ {
std::copy(persistentVid, persistentVid+(VIDXRES*YRES), vid); std::copy(persistentVid, persistentVid+(VIDXRES*YRES), vid);
@ -46,12 +59,12 @@ void Renderer::RenderBegin()
vid = warpVid; vid = warpVid;
std::fill(warpVid, warpVid+(VIDXRES*VIDYRES), 0); std::fill(warpVid, warpVid+(VIDXRES*VIDYRES), 0);
} }
#endif
//draw_air(); draw_air();
//draw_grav(); draw_grav();
render_parts(); render_parts();
//render_fire(); render_fire();
#ifndef OGLR
if(display_mode & DISPLAY_PERS) if(display_mode & DISPLAY_PERS)
{ {
int i,r,g,b; int i,r,g,b;
@ -69,17 +82,59 @@ void Renderer::RenderBegin()
persistentVid[i] = PIXRGB(r,g,b); persistentVid[i] = PIXRGB(r,g,b);
} }
} }
#endif
DrawWalls(); DrawWalls();
//draw_grav_zones(); draw_grav_zones();
//DrawSigns(); DrawSigns();
#ifndef OGLR
if(display_mode & DISPLAY_WARP) if(display_mode & DISPLAY_WARP)
{ {
vid = oldVid; vid = oldVid;
} }
#endif #endif
#ifndef OGLI #else
if(display_mode & DISPLAY_PERS)
{
std::copy(persistentVid, persistentVid+(VIDXRES*YRES), vid);
}
pixel * oldVid;
if(display_mode & DISPLAY_WARP)
{
oldVid = vid;
vid = warpVid;
std::fill(warpVid, warpVid+(VIDXRES*VIDYRES), 0);
}
draw_air();
draw_grav();
render_parts();
render_fire();
if(display_mode & DISPLAY_PERS)
{
int i,r,g,b;
for (i = 0; i < VIDXRES*YRES; i++)
{
r = PIXR(vid[i]);
g = PIXG(vid[i]);
b = PIXB(vid[i]);
if (r>0)
r--;
if (g>0)
g--;
if (b>0)
b--;
persistentVid[i] = PIXRGB(r,g,b);
}
}
DrawWalls();
draw_grav_zones();
DrawSigns();
if(display_mode & DISPLAY_WARP)
{
vid = oldVid;
}
FinaliseParts(); FinaliseParts();
#endif #endif
} }
@ -88,6 +143,8 @@ void Renderer::RenderEnd()
{ {
#ifdef OGLI #ifdef OGLI
#ifdef OGLR #ifdef OGLR
glTranslated(0, -MENUSIZE, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo);
FinaliseParts(); FinaliseParts();
RenderZoom(); RenderZoom();
#else #else
@ -348,7 +405,7 @@ void Renderer::RenderZoom()
glGetIntegerv(GL_BLEND_SRC, &origBlendSrc); glGetIntegerv(GL_BLEND_SRC, &origBlendSrc);
glGetIntegerv(GL_BLEND_DST, &origBlendDst); glGetIntegerv(GL_BLEND_DST, &origBlendDst);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);//glBlendFunc(GL_ONE, GL_ZERO); glBlendFunc(GL_ONE, GL_ZERO);
glEnable( GL_TEXTURE_2D ); glEnable( GL_TEXTURE_2D );
//glReadBuffer(GL_AUX0); //glReadBuffer(GL_AUX0);
@ -2393,6 +2450,19 @@ Renderer::Renderer(Graphics * g, Simulation * sim):
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
//Temptexture
glEnable(GL_TEXTURE_2D);
glGenTextures(1, &textTexture);
glBindTexture(GL_TEXTURE_2D, textTexture);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
loadShaders(); loadShaders();
#endif #endif
prepare_alpha(CELL, 1.0f); prepare_alpha(CELL, 1.0f);

View File

@ -85,6 +85,7 @@ public:
void checkProgram(GLuint program, char * progname); void checkProgram(GLuint program, char * progname);
void loadShaders(); void loadShaders();
GLuint vidBuf,textTexture; GLuint vidBuf,textTexture;
GLint prevFbo;
#endif #endif
pixel * vid; pixel * vid;
pixel * persistentVid; pixel * persistentVid;