X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fglforestfire.c;h=bcc9ed7fd47f76daae13d3b3a4cc169d8a61015a;hb=78add6e627ee5f10e1fa6f3852602ea5066eee5a;hp=6b365ad17be14162935fe0dce5bce439782b1030;hpb=c1b9b55ad8d59dc05ef55e316aebf5863e7dfa56;p=xscreensaver diff --git a/hacks/glx/glforestfire.c b/hacks/glx/glforestfire.c index 6b365ad1..bcc9ed7f 100644 --- a/hacks/glx/glforestfire.c +++ b/hacks/glx/glforestfire.c @@ -81,7 +81,6 @@ static const char sccsid[] = "@(#)fire.c 5.02 2001/09/26 xlockmore"; "*showFPS: False \n" \ "*wireframe: False \n" \ -# define refresh_fire 0 #define MODE_fire #include "xlockmore.h" /* from the xscreensaver distribution */ #include "gltrackball.h" @@ -96,16 +95,11 @@ static const char sccsid[] = "@(#)fire.c 5.02 2001/09/26 xlockmore"; #if defined( USE_XPM ) || defined( USE_XPMINC ) || defined(STANDALONE) /* USE_XPM & USE_XPMINC in xlock mode ; HAVE_XPM in xscreensaver mode */ -#include "xpm-ximage.h" +#include "ximage-loader.h" #define I_HAVE_XPM -#ifdef STANDALONE -#include "../images/ground.xpm" -#include "../images/tree.xpm" -#else /* !STANDALONE */ -#include "pixmaps/ground.xpm" -#include "pixmaps/tree.xpm" -#endif /* !STANDALONE */ +#include "images/gen/ground_png.h" +#include "images/gen/tree_png.h" #endif /* HAVE_XPM */ /* vector utility macros */ @@ -535,8 +529,10 @@ static void inittextures(ModeInfo * mi) glBindTexture(GL_TEXTURE_2D, fs->groundid); #endif /* HAVE_GLBINDTEXTURE */ - if ((fs->gtexture = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), - MI_COLORMAP(mi), ground)) == None) { + if ((fs->gtexture = image_data_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), + ground_png, + sizeof(ground_png))) + == None) { (void) fprintf(stderr, "Error reading the ground texture.\n"); glDeleteTextures(1, &fs->groundid); do_texture = False; @@ -549,10 +545,7 @@ static void inittextures(ModeInfo * mi) clear_gl_error(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fs->gtexture->width, fs->gtexture->height, 0, - GL_RGBA, - /* GL_UNSIGNED_BYTE, */ - GL_UNSIGNED_INT_8_8_8_8_REV, - fs->gtexture->data); + GL_RGBA, GL_UNSIGNED_BYTE, fs->gtexture->data); check_gl_error("texture"); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -569,8 +562,11 @@ static void inittextures(ModeInfo * mi) #ifdef HAVE_GLBINDTEXTURE glBindTexture(GL_TEXTURE_2D,fs->treeid); #endif /* HAVE_GLBINDTEXTURE */ - if ((fs->ttexture = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), - MI_COLORMAP(mi), tree)) == None) { + if ((fs->ttexture = image_data_to_ximage(MI_DISPLAY(mi), + MI_VISUAL(mi), + tree_png, + sizeof(tree_png))) + == None) { (void)fprintf(stderr,"Error reading tree texture.\n"); glDeleteTextures(1, &fs->treeid); fs->treeid = 0; @@ -581,10 +577,7 @@ static void inittextures(ModeInfo * mi) clear_gl_error(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fs->ttexture->width, fs->ttexture->height, 0, - GL_RGBA, - /* GL_UNSIGNED_BYTE, */ - GL_UNSIGNED_INT_8_8_8_8_REV, - fs->ttexture->data); + GL_RGBA, GL_UNSIGNED_BYTE, fs->ttexture->data); check_gl_error("texture"); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); @@ -621,13 +614,15 @@ static Bool inittree(ModeInfo * mi) return False; } /* initialise positions */ - for(i=0;inum_trees;i++) - do { - fs->treepos[i].x =vrnd()*TREEOUTR*2.0-TREEOUTR; - fs->treepos[i].y =0.0; - fs->treepos[i].z =vrnd()*TREEOUTR*2.0-TREEOUTR; - dist=sqrt(fs->treepos[i].x *fs->treepos[i].x +fs->treepos[i].z *fs->treepos[i].z ); - } while((distTREEOUTR)); + for(i=0;inum_trees;i++) { + do { + fs->treepos[i].x =vrnd()*TREEOUTR*2.0-TREEOUTR; + fs->treepos[i].y =0.0; + fs->treepos[i].z =vrnd()*TREEOUTR*2.0-TREEOUTR; + dist = sqrt(fs->treepos[i].x * fs->treepos[i].x + + fs->treepos[i].z * fs->treepos[i].z); + } while((distTREEOUTR)); + } return True; } @@ -853,23 +848,6 @@ static Bool Init(ModeInfo * mi) fs->eject_r, fs->ridtri); } - glShadeModel(GL_FLAT); - glEnable(GL_DEPTH_TEST); - - /* makes particles blend with background */ - if (!MI_IS_WIREFRAME(mi)||(!fs->np)) - { - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - } - - /* fog stuff */ - glEnable(GL_FOG); - glFogi(GL_FOG_MODE, GL_EXP); - glFogfv(GL_FOG_COLOR, fogcolor); - glFogf(GL_FOG_DENSITY, 0.03); - glHint(GL_FOG_HINT, GL_NICEST); - /* initialise particles and trees */ for (i = 0; i < fs->np; i++) { setnewpart(fs, &(fs->p[i])); @@ -902,9 +880,11 @@ static Bool Init(ModeInfo * mi) */ -static void -free_fire(firestruct *fs) +ENTRYPOINT void +free_fire(ModeInfo * mi) { + firestruct *fs = &fire[MI_SCREEN(mi)]; + if (mode_font != None && fs->fontbase != None) { glDeleteLists(fs->fontbase, mode_font->max_char_or_byte2 - mode_font->min_char_or_byte2 + 1); @@ -946,14 +926,7 @@ init_fire(ModeInfo * mi) { firestruct *fs; - /* allocate the main fire table if needed */ - if (fire == NULL) { - if ((fire = (firestruct *) calloc(MI_NUM_SCREENS(mi), - sizeof(firestruct))) == NULL) - return; - } - - /* initialise the per screen fire structure */ + MI_INIT (mi, fire); fs = &fire[MI_SCREEN(mi)]; fs->np = MI_COUNT(mi); fs->fog = do_fog; @@ -961,14 +934,14 @@ init_fire(ModeInfo * mi) /* initialise fire particles if any */ if ((fs->np)&&(fs->p == NULL)) { if ((fs->p = (part *) calloc(fs->np, sizeof(part))) == NULL) { - free_fire(fs); + free_fire(mi); return; } } else if (fs->r == NULL) { /* initialise rain particles if no fire particles */ if ((fs->r = (rain *) calloc(NUMPART, sizeof(part))) == NULL) { - free_fire(fs); + free_fire(mi); return; } } @@ -979,7 +952,7 @@ init_fire(ModeInfo * mi) else fs->num_trees = 0; - fs->trackball = gltrackball_init (); + fs->trackball = gltrackball_init (False); /* xlock GL stuff */ if ((fs->glx_context = init_GL(mi)) != NULL) { @@ -991,7 +964,7 @@ init_fire(ModeInfo * mi) #endif glDrawBuffer(GL_BACK); if (!Init(mi)) { - free_fire(fs); + free_fire(mi); return; } } else { @@ -1017,7 +990,28 @@ ENTRYPOINT void draw_fire(ModeInfo * mi) return; glXMakeCurrent(display, window, *(fs->glx_context)); + + glShadeModel(GL_FLAT); + glEnable(GL_DEPTH_TEST); + + /* makes particles blend with background */ + if (!MI_IS_WIREFRAME(mi)||(!fs->np)) + { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + } + + /* fog stuff */ + glEnable(GL_FOG); + glFogi(GL_FOG_MODE, GL_EXP); + glFogfv(GL_FOG_COLOR, fogcolor); + glFogf(GL_FOG_DENSITY, 0.03); + glHint(GL_FOG_HINT, GL_NICEST); + + glPushMatrix(); + glRotatef(current_device_rotation(), 0, 0, 1); DrawFire(mi); + glPopMatrix(); #ifndef STANDALONE Reshape(mi); /* xlock mode */ #else @@ -1039,13 +1033,6 @@ ENTRYPOINT void draw_fire(ModeInfo * mi) ENTRYPOINT void release_fire(ModeInfo * mi) { - if (fire != NULL) { - int screen; - for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) - free_fire(&fire[screen]); - (void) free((void *) fire); - fire = (firestruct *) NULL; - } if (mode_font != None) { /* only free-ed when there are no more screens used */ @@ -1060,43 +1047,10 @@ fire_handle_event (ModeInfo *mi, XEvent *event) { firestruct *fs = &fire[MI_SCREEN(mi)]; - if (event->xany.type == ButtonPress && - event->xbutton.button == Button1) - { - fs->button_down_p = True; - event->xbutton.x = MI_WIDTH(mi) - event->xbutton.x; /* kludge! */ - event->xbutton.y = MI_HEIGHT(mi) - event->xbutton.y; - gltrackball_start (fs->trackball, - event->xbutton.x, event->xbutton.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } - else if (event->xany.type == ButtonRelease && - event->xbutton.button == Button1) - { - fs->button_down_p = False; - return True; - } - else if (event->xany.type == ButtonPress && - (event->xbutton.button == Button4 || - event->xbutton.button == Button5 || - event->xbutton.button == Button6 || - event->xbutton.button == Button7)) - { - gltrackball_mousewheel (fs->trackball, event->xbutton.button, 5, - !!event->xbutton.state); - return True; - } - else if (event->xany.type == MotionNotify && - fs->button_down_p) - { - event->xmotion.x = MI_WIDTH(mi) - event->xmotion.x; /* kludge! */ - event->xmotion.y = MI_HEIGHT(mi) - event->xmotion.y; - gltrackball_track (fs->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } + if (gltrackball_event_handler (event, fs->trackball, + MI_WIDTH (mi), MI_HEIGHT (mi), + &fs->button_down_p)) + return True; return False; }