diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2011-10-24 16:20:18 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2011-10-24 16:20:18 (GMT) |
| commit | 8f91f948c1082b09eba53f01704e98abc6bd611e (patch) | |
| tree | 2c86c6d8963cc867752eb61bf0c319662b91f7f3 /src | |
| parent | 66fd41673b5e1c3a2d86af1a6f0c7f565639a482 (diff) | |
| download | powder-8f91f948c1082b09eba53f01704e98abc6bd611e.zip powder-8f91f948c1082b09eba53f01704e98abc6bd611e.tar.gz | |
Generate fire/plasma gradients at runtime, makes editing easier
Diffstat (limited to 'src')
| -rw-r--r-- | src/elements/fire.c | 2 | ||||
| -rw-r--r-- | src/elements/newgraphics.c | 2 | ||||
| -rw-r--r-- | src/elements/plsm.c | 3 | ||||
| -rw-r--r-- | src/graphics.c | 63 | ||||
| -rw-r--r-- | src/main.c | 2 |
5 files changed, 67 insertions, 5 deletions
diff --git a/src/elements/fire.c b/src/elements/fire.c index b16b679..6dc620e 100644 --- a/src/elements/fire.c +++ b/src/elements/fire.c @@ -2,7 +2,7 @@ int graphics_FIRE(GRAPHICS_FUNC_ARGS) { - int caddress = restrict_flt(restrict_flt((float)((int)(cpart->life/2)), 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3); + int caddress = restrict_flt(restrict_flt((float)cpart->life, 0.0f, 200.0f)*3, 0.0f, (200.0f*3)-3); *colr = (unsigned char)flm_data[caddress]; *colg = (unsigned char)flm_data[caddress+1]; *colb = (unsigned char)flm_data[caddress+2]; diff --git a/src/elements/newgraphics.c b/src/elements/newgraphics.c index 2f7be03..7a8fc32 100644 --- a/src/elements/newgraphics.c +++ b/src/elements/newgraphics.c @@ -1,4 +1,6 @@ #include <element.h> +#include "hmap.h" + int graphics_QRTZ(GRAPHICS_FUNC_ARGS) //QRTZ and PQRT { int t = cpart->type, z = cpart->tmp - 5;//speckles! diff --git a/src/elements/plsm.c b/src/elements/plsm.c index 6cd0275..7fa99bb 100644 --- a/src/elements/plsm.c +++ b/src/elements/plsm.c @@ -1,4 +1,5 @@ #include <element.h> +#include "hmap.h" int graphics_PLSM(GRAPHICS_FUNC_ARGS) { @@ -12,7 +13,7 @@ int graphics_PLSM(GRAPHICS_FUNC_ARGS) *fireg = *colg; *fireb = *colb; - *pixel_mode = PMODE_NONE; //Clear default, don't draw pixel + *pixel_mode = PMODE_GLOW; //Clear default, don't draw pixel *pixel_mode |= FIRE_ADD; //Returning 0 means dynamic, do not cache return 0; diff --git a/src/graphics.c b/src/graphics.c index 43befe0..c52fb1b 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -21,7 +21,7 @@ #define INCLUDE_FONTDATA #include <font.h> #include <misc.h> - +#include "hmap.h" unsigned cmode = CM_FIRE; SDL_Surface *sdl_scrn; @@ -44,6 +44,63 @@ unsigned int fire_alpha[CELL*3][CELL*3]; pixel *fire_bg; pixel *pers_bg; +char * flm_data; +int flm_data_points = 4; +pixel flm_data_colours[] = {PIXPACK(0xAF9F0F), PIXPACK(0xDFBF0F), PIXPACK(0x60300F), PIXPACK(0x000000)}; +float flm_data_pos[] = {1.0f, 0.9f, 0.5f, 0.0f}; + +char * plasma_data; +int plasma_data_points = 5; +pixel plasma_data_colours[] = {PIXPACK(0xAFFFFF), PIXPACK(0xAFFFFF), PIXPACK(0x301060), PIXPACK(0x301040), PIXPACK(0x000000)}; +float plasma_data_pos[] = {1.0f, 0.9f, 0.5f, 0.25, 0.0f}; + +char * generate_gradient(pixel * colours, float * points, int pointcount, int size) +{ + int cp, i, j; + pixel ptemp; + char * newdata = malloc(size * 3); + float poss, pose, temp; + memset(newdata, 0, size*3); + //Sort the Colours and Points + for (i = (pointcount - 1); i > 0; i--) + { + for (j = 1; j <= i; j++) + { + if (points[j-1] > points[j]) + { + temp = points[j-1]; + points[j-1] = points[j]; + points[j] = temp; + + ptemp = colours[j-1]; + colours[j-1] = colours[j]; + colours[j] = ptemp; + } + } + } + i = 0; + j = 1; + poss = points[i]; + pose = points[j]; + for (cp = 0; cp < size; cp++) + { + float cpos = (float)cp / (float)size, ccpos, cccpos; + if(cpos > pose && j+1 < pointcount) + { + poss = points[++i]; + pose = points[++j]; + } + ccpos = cpos - poss; + cccpos = ccpos / (pose - poss); + if(cccpos > 1.0f) + cccpos = 1.0f; + newdata[(cp*3)] = PIXR(colours[i])*(1.0f-cccpos) + PIXR(colours[j])*(cccpos); + newdata[(cp*3)+1] = PIXG(colours[i])*(1.0f-cccpos) + PIXG(colours[j])*(cccpos); + newdata[(cp*3)+2] = PIXB(colours[i])*(1.0f-cccpos) + PIXB(colours[j])*(cccpos); + } + return newdata; +} + void *ptif_pack(pixel *src, int w, int h, int *result_size){ int i = 0, datalen = (w*h)*3, cx = 0, cy = 0; unsigned char *red_chan = calloc(1, w*h); @@ -3481,8 +3538,8 @@ int sdl_open(void) glGenTextures(1, &partsFboTex); glBindTexture(GL_TEXTURE_2D, partsFboTex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, XRES, YRES, 0, GL_RGBA, GL_FLOAT, NULL); - 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_MAG_FILTER,GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); //FBO glGenFramebuffers(1, &partsFbo); @@ -1741,6 +1741,8 @@ int main(int argc, char *argv[]) prepare_alpha(CELL, 1.0f); prepare_graphicscache(); + flm_data = generate_gradient(flm_data_colours, flm_data_pos, flm_data_points, 200); + plasma_data = generate_gradient(plasma_data_colours, plasma_data_pos, plasma_data_points, 200); if (cpu_check()) { |
