From 09d3cacf9cb3ee0098df6d0ea34dc39b608f6931 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Thu, 20 Oct 2011 16:28:49 +0100 Subject: [PATCH] Implement Blur mode and embed shaders --- includes/graphics.h | 13 ++++++++++ src/elements/deut.c | 9 +++---- src/graphics.c | 63 ++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 73 insertions(+), 12 deletions(-) diff --git a/includes/graphics.h b/includes/graphics.h index 35fb4dc3b..a5703964f 100644 --- a/includes/graphics.h +++ b/includes/graphics.h @@ -191,3 +191,16 @@ void ogl_blit(int x, int y, int w, int h, pixel *src, int pitch, int scale); #endif #endif + +#ifdef INCLUDE_SHADERS +const char * fragment = "uniform sampler2D fireAlpha;\ +void main () {\ + vec4 texColor = texture2D(fireAlpha, gl_PointCoord);\ + gl_FragColor = vec4(gl_Color.rgb, texColor.a*gl_Color.a);\ +}"; +const char * vertex = "void main(void)\ +{\ + gl_Position = ftransform();;\ + gl_FrontColor = gl_Color;\ +}"; +#endif diff --git a/src/elements/deut.c b/src/elements/deut.c index 376f5f9e6..bee375399 100644 --- a/src/elements/deut.c +++ b/src/elements/deut.c @@ -73,11 +73,10 @@ int graphics_DEUT(GRAPHICS_FUNC_ARGS) { if(parts[i].life>=700) { - *firea = 20; - *firer = *fireg = *fireb = 255; - - *pixel_mode |= FIRE_ADD; - *pixel_mode &= ~PMODE; + *colr += parts[i].life*1; + *colg += parts[i].life*2; + *colb += parts[i].life*3; + *pixel_mode |= PMODE_GLOW; } else { diff --git a/src/graphics.c b/src/graphics.c index 182df0b6f..61865d7c7 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -15,6 +15,7 @@ #include #include #include +#define INCLUDE_SHADERS #include #include #define INCLUDE_FONTDATA @@ -26,7 +27,7 @@ unsigned cmode = CM_FIRE; SDL_Surface *sdl_scrn; int sdl_scale = 1; -GLuint vidBuf, airBuf, fireAlpha, glowAlpha, fireProg; +GLuint vidBuf, airBuf, fireAlpha, glowAlpha, blurAlpha, fireProg; int sandcolour_r = 0; int sandcolour_g = 0; @@ -1824,7 +1825,7 @@ void render_parts(pixel *vid) // -- END FLAT -- // } - if(cglow) + if(cglow || cblur) { // -- BEGIN GLOW -- // //Start and prepare fire program @@ -1846,12 +1847,27 @@ void render_parts(pixel *vid) glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glColorPointer(4, GL_FLOAT, 0, &glowC[0]); - glVertexPointer(2, GL_INT, 0, &glowV[0]); - - glDrawArrays(GL_POINTS, 0, cglow); + if(cglow) + { + glColorPointer(4, GL_FLOAT, 0, &glowC[0]); + glVertexPointer(2, GL_INT, 0, &glowV[0]); + + glDrawArrays(GL_POINTS, 0, cglow); + } + + glPointSize(7.0f); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + if(cblur) + { + glBindTexture(GL_TEXTURE_2D, blurAlpha); + + glColorPointer(4, GL_FLOAT, 0, &blurC[0]); + glVertexPointer(2, GL_INT, 0, &blurV[0]); + + glDrawArrays(GL_POINTS, 0, cblur); + } //Clear some stuff we set glDisable(GL_POINT_SPRITE); @@ -2432,6 +2448,7 @@ void prepare_alpha(int size, float intensity) float temp[CELL*3][CELL*3]; float fire_alphaf[CELL*3][CELL*3]; float glow_alphaf[11][11]; + float blur_alphaf[7][7]; memset(temp, 0, sizeof(temp)); for (x=0; x