Persistent mode

This commit is contained in:
Simon Robertshaw
2012-08-09 00:57:35 +01:00
parent d352a10d80
commit bb99efdedf
2 changed files with 313 additions and 286 deletions

View File

@@ -24,8 +24,8 @@ extern "C"
} }
#ifndef OGLI #ifndef OGLI
#define VIDXRES XRES+BARSIZE #define VIDXRES (XRES+BARSIZE)
#define VIDYRES YRES+MENUSIZE #define VIDYRES (YRES+MENUSIZE)
#else #else
#define VIDXRES XRES #define VIDXRES XRES
#define VIDYRES YRES #define VIDYRES YRES
@@ -37,11 +37,35 @@ extern "C"
void Renderer::RenderBegin() void Renderer::RenderBegin()
{ {
#ifndef OGLR
if(display_mode & DISPLAY_PERS)
{
std::copy(persistentVid, persistentVid+(VIDXRES*YRES), vid);
}
#endif
draw_air(); draw_air();
draw_grav(); draw_grav();
render_parts(); render_parts();
render_fire(); render_fire();
#ifndef OGLR
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);
}
}
#endif
DrawWalls(); DrawWalls();
draw_grav_zones(); draw_grav_zones();
DrawSigns(); DrawSigns();
@@ -69,9 +93,9 @@ void Renderer::clearScreen(float alpha)
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo);
} }
else else
{ {
glBlendEquation(GL_FUNC_REVERSE_SUBTRACT); glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
glColor4f(1.0f, 1.0f, 1.0f, alpha); glColor4f(1.0f, 1.0f, 1.0f, alpha);
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo);
@@ -84,12 +108,12 @@ void Renderer::clearScreen(float alpha)
glEnd(); glEnd();
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo);
glBlendEquation(GL_FUNC_ADD); glBlendEquation(GL_FUNC_ADD);
} }
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT);
#endif #endif
#ifdef OGLI #ifdef OGLI
std::fill(vid, vid+(VIDXRES*VIDYRES), 0); std::fill(vid, vid+(VIDXRES*VIDYRES), 0);
#endif #endif
} }
#ifdef OGLR #ifdef OGLR
@@ -1259,57 +1283,57 @@ void Renderer::render_parts()
if(pixel_mode & PMODE_FLAT) if(pixel_mode & PMODE_FLAT)
{ {
#ifdef OGLR #ifdef OGLR
flatV[cflatV++] = nx; flatV[cflatV++] = nx;
flatV[cflatV++] = ny; flatV[cflatV++] = ny;
flatC[cflatC++] = ((float)colr)/255.0f; flatC[cflatC++] = ((float)colr)/255.0f;
flatC[cflatC++] = ((float)colg)/255.0f; flatC[cflatC++] = ((float)colg)/255.0f;
flatC[cflatC++] = ((float)colb)/255.0f; flatC[cflatC++] = ((float)colb)/255.0f;
flatC[cflatC++] = 1.0f; flatC[cflatC++] = 1.0f;
cflat++; cflat++;
#else #else
vid[ny*(VIDXRES)+nx] = PIXRGB(colr,colg,colb); vid[ny*(VIDXRES)+nx] = PIXRGB(colr,colg,colb);
#endif #endif
} }
if(pixel_mode & PMODE_BLEND) if(pixel_mode & PMODE_BLEND)
{ {
#ifdef OGLR #ifdef OGLR
flatV[cflatV++] = nx; flatV[cflatV++] = nx;
flatV[cflatV++] = ny; flatV[cflatV++] = ny;
flatC[cflatC++] = ((float)colr)/255.0f; flatC[cflatC++] = ((float)colr)/255.0f;
flatC[cflatC++] = ((float)colg)/255.0f; flatC[cflatC++] = ((float)colg)/255.0f;
flatC[cflatC++] = ((float)colb)/255.0f; flatC[cflatC++] = ((float)colb)/255.0f;
flatC[cflatC++] = ((float)cola)/255.0f; flatC[cflatC++] = ((float)cola)/255.0f;
cflat++; cflat++;
#else #else
blendpixel(nx, ny, colr, colg, colb, cola); blendpixel(nx, ny, colr, colg, colb, cola);
#endif #endif
} }
if(pixel_mode & PMODE_ADD) if(pixel_mode & PMODE_ADD)
{ {
#ifdef OGLR #ifdef OGLR
addV[caddV++] = nx; addV[caddV++] = nx;
addV[caddV++] = ny; addV[caddV++] = ny;
addC[caddC++] = ((float)colr)/255.0f; addC[caddC++] = ((float)colr)/255.0f;
addC[caddC++] = ((float)colg)/255.0f; addC[caddC++] = ((float)colg)/255.0f;
addC[caddC++] = ((float)colb)/255.0f; addC[caddC++] = ((float)colb)/255.0f;
addC[caddC++] = ((float)cola)/255.0f; addC[caddC++] = ((float)cola)/255.0f;
cadd++; cadd++;
#else #else
addpixel(nx, ny, colr, colg, colb, cola); addpixel(nx, ny, colr, colg, colb, cola);
#endif #endif
} }
if(pixel_mode & PMODE_BLOB) if(pixel_mode & PMODE_BLOB)
{ {
#ifdef OGLR #ifdef OGLR
blobV[cblobV++] = nx; blobV[cblobV++] = nx;
blobV[cblobV++] = ny; blobV[cblobV++] = ny;
blobC[cblobC++] = ((float)colr)/255.0f; blobC[cblobC++] = ((float)colr)/255.0f;
blobC[cblobC++] = ((float)colg)/255.0f; blobC[cblobC++] = ((float)colg)/255.0f;
blobC[cblobC++] = ((float)colb)/255.0f; blobC[cblobC++] = ((float)colb)/255.0f;
blobC[cblobC++] = 1.0f; blobC[cblobC++] = 1.0f;
cblob++; cblob++;
#else #else
vid[ny*(VIDXRES)+nx] = PIXRGB(colr,colg,colb); vid[ny*(VIDXRES)+nx] = PIXRGB(colr,colg,colb);
blendpixel(nx+1, ny, colr, colg, colb, 223); blendpixel(nx+1, ny, colr, colg, colb, 223);
blendpixel(nx-1, ny, colr, colg, colb, 223); blendpixel(nx-1, ny, colr, colg, colb, 223);
@@ -1326,19 +1350,19 @@ void Renderer::render_parts()
{ {
int cola1 = (5*cola)/255; int cola1 = (5*cola)/255;
#ifdef OGLR #ifdef OGLR
glowV[cglowV++] = nx; glowV[cglowV++] = nx;
glowV[cglowV++] = ny; glowV[cglowV++] = ny;
glowC[cglowC++] = ((float)colr)/255.0f; glowC[cglowC++] = ((float)colr)/255.0f;
glowC[cglowC++] = ((float)colg)/255.0f; glowC[cglowC++] = ((float)colg)/255.0f;
glowC[cglowC++] = ((float)colb)/255.0f; glowC[cglowC++] = ((float)colb)/255.0f;
glowC[cglowC++] = 1.0f; glowC[cglowC++] = 1.0f;
cglow++; cglow++;
#else #else
addpixel(nx, ny, colr, colg, colb, (192*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-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);
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++) { for (x = 1; x < 6; x++) {
addpixel(nx, ny-x, colr, colg, colb, cola1); addpixel(nx, ny-x, colr, colg, colb, cola1);
@@ -1359,13 +1383,13 @@ void Renderer::render_parts()
if(pixel_mode & PMODE_BLUR) if(pixel_mode & PMODE_BLUR)
{ {
#ifdef OGLR #ifdef OGLR
blurV[cblurV++] = nx; blurV[cblurV++] = nx;
blurV[cblurV++] = ny; blurV[cblurV++] = ny;
blurC[cblurC++] = ((float)colr)/255.0f; blurC[cblurC++] = ((float)colr)/255.0f;
blurC[cblurC++] = ((float)colg)/255.0f; blurC[cblurC++] = ((float)colg)/255.0f;
blurC[cblurC++] = ((float)colb)/255.0f; blurC[cblurC++] = ((float)colb)/255.0f;
blurC[cblurC++] = 1.0f; blurC[cblurC++] = 1.0f;
cblur++; cblur++;
#else #else
for (x=-3; x<4; x++) for (x=-3; x<4; x++)
{ {
@@ -1386,53 +1410,53 @@ void Renderer::render_parts()
flicker = rand()%20; flicker = rand()%20;
#ifdef OGLR #ifdef OGLR
//Oh god, this is awful //Oh god, this is awful
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx-5; lineV[clineV++] = fnx-5;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 1.0f - ((float)flicker)/30; lineC[clineC++] = 1.0f - ((float)flicker)/30;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx+5; lineV[clineV++] = fnx+5;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny-5; lineV[clineV++] = fny-5;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 1.0f - ((float)flicker)/30; lineC[clineC++] = 1.0f - ((float)flicker)/30;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny+5; lineV[clineV++] = fny+5;
cline++; cline++;
#else #else
gradv = 4*sim->parts[i].life + flicker; gradv = 4*sim->parts[i].life + flicker;
for (x = 0; gradv>0.5; x++) { for (x = 0; gradv>0.5; x++) {
@@ -1450,53 +1474,53 @@ void Renderer::render_parts()
flicker = rand()%20; flicker = rand()%20;
#ifdef OGLR #ifdef OGLR
//Oh god, this is awful //Oh god, this is awful
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx-10; lineV[clineV++] = fnx-10;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 1.0f - ((float)flicker)/40; lineC[clineC++] = 1.0f - ((float)flicker)/40;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx+10; lineV[clineV++] = fnx+10;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny-10; lineV[clineV++] = fny-10;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 1.0f - ((float)flicker)/30; lineC[clineC++] = 1.0f - ((float)flicker)/30;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny+10; lineV[clineV++] = fny+10;
cline++; cline++;
#else #else
gradv = flicker + fabs(parts[i].vx)*17 + fabs(sim->parts[i].vy)*17; gradv = flicker + fabs(parts[i].vx)*17 + fabs(sim->parts[i].vy)*17;
blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) );
@@ -1523,53 +1547,53 @@ void Renderer::render_parts()
flicker = rand()%20; flicker = rand()%20;
#ifdef OGLR #ifdef OGLR
//Oh god, this is awful //Oh god, this is awful
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx-70; lineV[clineV++] = fnx-70;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 1.0f - ((float)flicker)/30; lineC[clineC++] = 1.0f - ((float)flicker)/30;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx+70; lineV[clineV++] = fnx+70;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny-70; lineV[clineV++] = fny-70;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 1.0f - ((float)flicker)/50; lineC[clineC++] = 1.0f - ((float)flicker)/50;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny; lineV[clineV++] = fny;
cline++; cline++;
lineC[clineC++] = ((float)colr)/255.0f; lineC[clineC++] = ((float)colr)/255.0f;
lineC[clineC++] = ((float)colg)/255.0f; lineC[clineC++] = ((float)colg)/255.0f;
lineC[clineC++] = ((float)colb)/255.0f; lineC[clineC++] = ((float)colb)/255.0f;
lineC[clineC++] = 0.0f; lineC[clineC++] = 0.0f;
lineV[clineV++] = fnx; lineV[clineV++] = fnx;
lineV[clineV++] = fny+70; lineV[clineV++] = fny+70;
cline++; cline++;
#else #else
gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17; gradv = flicker + fabs(parts[i].vx)*17 + fabs(parts[i].vy)*17;
blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) ); blendpixel(nx, ny, colr, colg, colb, (gradv*4)>255?255:(gradv*4) );
@@ -1650,13 +1674,13 @@ void Renderer::render_parts()
if(firea && (pixel_mode & FIRE_BLEND)) if(firea && (pixel_mode & FIRE_BLEND))
{ {
#ifdef OGLR #ifdef OGLR
smokeV[csmokeV++] = nx; smokeV[csmokeV++] = nx;
smokeV[csmokeV++] = ny; smokeV[csmokeV++] = ny;
smokeC[csmokeC++] = ((float)firer)/255.0f; smokeC[csmokeC++] = ((float)firer)/255.0f;
smokeC[csmokeC++] = ((float)fireg)/255.0f; smokeC[csmokeC++] = ((float)fireg)/255.0f;
smokeC[csmokeC++] = ((float)fireb)/255.0f; smokeC[csmokeC++] = ((float)fireb)/255.0f;
smokeC[csmokeC++] = ((float)firea)/255.0f; smokeC[csmokeC++] = ((float)firea)/255.0f;
csmoke++; csmoke++;
#else #else
firea /= 2; firea /= 2;
fire_r[ny/CELL][nx/CELL] = (firea*firer + (255-firea)*fire_r[ny/CELL][nx/CELL]) >> 8; fire_r[ny/CELL][nx/CELL] = (firea*firer + (255-firea)*fire_r[ny/CELL][nx/CELL]) >> 8;
@@ -1667,13 +1691,13 @@ void Renderer::render_parts()
if(firea && (pixel_mode & FIRE_ADD)) if(firea && (pixel_mode & FIRE_ADD))
{ {
#ifdef OGLR #ifdef OGLR
fireV[cfireV++] = nx; fireV[cfireV++] = nx;
fireV[cfireV++] = ny; fireV[cfireV++] = ny;
fireC[cfireC++] = ((float)firer)/255.0f; fireC[cfireC++] = ((float)firer)/255.0f;
fireC[cfireC++] = ((float)fireg)/255.0f; fireC[cfireC++] = ((float)fireg)/255.0f;
fireC[cfireC++] = ((float)fireb)/255.0f; fireC[cfireC++] = ((float)fireb)/255.0f;
fireC[cfireC++] = ((float)firea)/255.0f; fireC[cfireC++] = ((float)firea)/255.0f;
cfire++; cfire++;
#else #else
firea /= 8; firea /= 8;
firer = ((firea*firer) >> 8) + fire_r[ny/CELL][nx/CELL]; firer = ((firea*firer) >> 8) + fire_r[ny/CELL][nx/CELL];
@@ -1697,46 +1721,46 @@ void Renderer::render_parts()
} }
#ifdef OGLR #ifdef OGLR
//Go into array mode //Go into array mode
glEnableClientState(GL_COLOR_ARRAY); glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
if(cflat) if(cflat)
{ {
// -- BEGIN FLAT -- // // -- BEGIN FLAT -- //
//Set point size (size of fire texture) //Set point size (size of fire texture)
glPointSize(1.0f); glPointSize(1.0f);
glColorPointer(4, GL_FLOAT, 0, &flatC[0]); glColorPointer(4, GL_FLOAT, 0, &flatC[0]);
glVertexPointer(2, GL_INT, 0, &flatV[0]); glVertexPointer(2, GL_INT, 0, &flatV[0]);
glDrawArrays(GL_POINTS, 0, cflat); glDrawArrays(GL_POINTS, 0, cflat);
//Clear some stuff we set //Clear some stuff we set
// -- END FLAT -- // // -- END FLAT -- //
} }
if(cblob) if(cblob)
{ {
// -- BEGIN BLOB -- // // -- BEGIN BLOB -- //
glEnable( GL_POINT_SMOOTH ); //Blobs! glEnable( GL_POINT_SMOOTH ); //Blobs!
glPointSize(2.5f); glPointSize(2.5f);
glColorPointer(4, GL_FLOAT, 0, &blobC[0]); glColorPointer(4, GL_FLOAT, 0, &blobC[0]);
glVertexPointer(2, GL_INT, 0, &blobV[0]); glVertexPointer(2, GL_INT, 0, &blobV[0]);
glDrawArrays(GL_POINTS, 0, cblob); glDrawArrays(GL_POINTS, 0, cblob);
//Clear some stuff we set //Clear some stuff we set
glDisable( GL_POINT_SMOOTH ); glDisable( GL_POINT_SMOOTH );
// -- END BLOB -- // // -- END BLOB -- //
} }
if(cglow || cblur) if(cglow || cblur)
{ {
// -- BEGIN GLOW -- // // -- BEGIN GLOW -- //
//Start and prepare fire program //Start and prepare fire program
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glUseProgram(fireProg); glUseProgram(fireProg);
@@ -1778,46 +1802,46 @@ void Renderer::render_parts()
glDrawArrays(GL_POINTS, 0, cblur); glDrawArrays(GL_POINTS, 0, cblur);
} }
//Clear some stuff we set //Clear some stuff we set
glDisable(GL_POINT_SPRITE); glDisable(GL_POINT_SPRITE);
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
glUseProgram(0); glUseProgram(0);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
// -- END GLOW -- // // -- END GLOW -- //
} }
if(cadd) if(cadd)
{ {
// -- BEGIN ADD -- // // -- BEGIN ADD -- //
//Set point size (size of fire texture) //Set point size (size of fire texture)
glPointSize(1.0f); glPointSize(1.0f);
glColorPointer(4, GL_FLOAT, 0, &addC[0]); glColorPointer(4, GL_FLOAT, 0, &addC[0]);
glVertexPointer(2, GL_INT, 0, &addV[0]); glVertexPointer(2, GL_INT, 0, &addV[0]);
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDrawArrays(GL_POINTS, 0, cadd); glDrawArrays(GL_POINTS, 0, cadd);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//Clear some stuff we set //Clear some stuff we set
// -- END ADD -- // // -- END ADD -- //
} }
if(cline) if(cline)
{ {
// -- BEGIN LINES -- // // -- BEGIN LINES -- //
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glEnable( GL_LINE_SMOOTH ); glEnable( GL_LINE_SMOOTH );
glColorPointer(4, GL_FLOAT, 0, &lineC[0]); glColorPointer(4, GL_FLOAT, 0, &lineC[0]);
glVertexPointer(2, GL_FLOAT, 0, &lineV[0]); glVertexPointer(2, GL_FLOAT, 0, &lineV[0]);
glDrawArrays(GL_LINE_STRIP, 0, cline); glDrawArrays(GL_LINE_STRIP, 0, cline);
//Clear some stuff we set //Clear some stuff we set
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_LINE_SMOOTH); glDisable(GL_LINE_SMOOTH);
// -- END LINES -- // // -- END LINES -- //
} }
if(cfire || csmoke) if(cfire || csmoke)
{ {
@@ -1857,23 +1881,23 @@ void Renderer::render_parts()
glDrawArrays(GL_POINTS, 0, csmoke); glDrawArrays(GL_POINTS, 0, csmoke);
} }
//Clear some stuff we set //Clear some stuff we set
glDisable(GL_POINT_SPRITE); glDisable(GL_POINT_SPRITE);
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
glUseProgram(0); glUseProgram(0);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
// -- END FIRE -- // // -- END FIRE -- //
} }
glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY);
//Reset FBO //Reset FBO
glTranslated(0, -MENUSIZE, 0); glTranslated(0, -MENUSIZE, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo);
glBlendFunc(origBlendSrc, origBlendDst); glBlendFunc(origBlendSrc, origBlendDst);
#endif #endif
} }
@@ -2047,44 +2071,44 @@ void Renderer::draw_air()
return; return;
} }
glEnable( GL_TEXTURE_2D ); glEnable( GL_TEXTURE_2D );
glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo); glGetIntegerv(GL_FRAMEBUFFER_BINDING, &prevFbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo);
glTranslated(0, MENUSIZE, 0); glTranslated(0, MENUSIZE, 0);
glUseProgram(airProg); glUseProgram(airProg);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, airVX); glBindTexture(GL_TEXTURE_2D, airVX);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_RED, GL_FLOAT, sim->air->vx); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_RED, GL_FLOAT, sim->air->vx);
glUniform1i(glGetUniformLocation(airProg, "airX"), 0); glUniform1i(glGetUniformLocation(airProg, "airX"), 0);
glActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, airVY); glBindTexture(GL_TEXTURE_2D, airVY);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_GREEN, GL_FLOAT, sim->air->vy); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_GREEN, GL_FLOAT, sim->air->vy);
glUniform1i(glGetUniformLocation(airProg, "airY"), 1); glUniform1i(glGetUniformLocation(airProg, "airY"), 1);
glActiveTexture(GL_TEXTURE2); glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, airPV); glBindTexture(GL_TEXTURE_2D, airPV);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_BLUE, GL_FLOAT, sim->air->pv); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, XRES/CELL, YRES/CELL, GL_BLUE, GL_FLOAT, sim->air->pv);
glUniform1i(glGetUniformLocation(airProg, "airP"), 2); glUniform1i(glGetUniformLocation(airProg, "airP"), 2);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2d(1, 1); glTexCoord2d(1, 1);
glVertex3f(XRES*sdl_scale, YRES*sdl_scale, 1.0); glVertex3f(XRES*sdl_scale, YRES*sdl_scale, 1.0);
glTexCoord2d(0, 1); glTexCoord2d(0, 1);
glVertex3f(0, YRES*sdl_scale, 1.0); glVertex3f(0, YRES*sdl_scale, 1.0);
glTexCoord2d(0, 0); glTexCoord2d(0, 0);
glVertex3f(0, 0, 1.0); glVertex3f(0, 0, 1.0);
glTexCoord2d(1, 0); glTexCoord2d(1, 0);
glVertex3f(XRES*sdl_scale, 0, 1.0); glVertex3f(XRES*sdl_scale, 0, 1.0);
glEnd(); glEnd();
glUseProgram(0); glUseProgram(0);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glTranslated(0, -MENUSIZE, 0); glTranslated(0, -MENUSIZE, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, prevFbo);
glDisable( GL_TEXTURE_2D ); glDisable( GL_TEXTURE_2D );
#endif #endif
} }
@@ -2146,6 +2170,7 @@ Renderer::Renderer(Graphics * g, Simulation * sim):
#else #else
vid = g->vid; vid = g->vid;
#endif #endif
persistentVid = new pixel[VIDXRES*YRES];
#endif #endif
memset(fire_r, 0, sizeof(fire_r)); memset(fire_r, 0, sizeof(fire_r));
@@ -2325,6 +2350,7 @@ void Renderer::ClearAccumulation()
std::fill(fire_r[0]+0, fire_r[(YRES/CELL)-1]+((XRES/CELL)-1), 0); std::fill(fire_r[0]+0, fire_r[(YRES/CELL)-1]+((XRES/CELL)-1), 0);
std::fill(fire_g[0]+0, fire_g[(YRES/CELL)-1]+((XRES/CELL)-1), 0); std::fill(fire_g[0]+0, fire_g[(YRES/CELL)-1]+((XRES/CELL)-1), 0);
std::fill(fire_b[0]+0, fire_b[(YRES/CELL)-1]+((XRES/CELL)-1), 0); std::fill(fire_b[0]+0, fire_b[(YRES/CELL)-1]+((XRES/CELL)-1), 0);
std::fill(persistentVid, persistentVid+(VIDXRES*YRES), 0);
} }
void Renderer::AddRenderMode(unsigned int mode) void Renderer::AddRenderMode(unsigned int mode)

View File

@@ -87,6 +87,7 @@ public:
void loadShaders(); void loadShaders();
#else #else
pixel * vid; pixel * vid;
pixel * persistentVid;
void blendpixel(int x, int y, int r, int g, int b, int a); 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 addpixel(int x, int y, int r, int g, int b, int a);