X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fglx%2Fgflux.c;h=69636f276d18f9a8f436f8b0978565addfda9426;hp=e5e58ae99656b798b32fec4916899c66a6ae5561;hb=4361b69d3178d7fc98d0388f9a223af6c2651aba;hpb=6b1c86cf395f59389e4ece4ea8f4bea2c332745b diff --git a/hacks/glx/gflux.c b/hacks/glx/gflux.c index e5e58ae9..69636f27 100644 --- a/hacks/glx/gflux.c +++ b/hacks/glx/gflux.c @@ -42,11 +42,12 @@ #ifdef STANDALONE #define DEFAULTS "*delay: 20000\n" \ "*showFPS: False\n" \ - "*mode: light\n" \ - "*useSHM: True \n" - + "*mode: grab\n" \ + "*useSHM: True \n" \ + "*suppressRotationAnimation: True\n" \ # define refresh_gflux 0 +# define release_gflux 0 # include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ @@ -76,6 +77,22 @@ static enum {wire=0,solid,light,checker,grab} _draw; +# define DEF_SQUARES "19" +# define DEF_RESOLUTION "4" +# define DEF_DRAW "2" +# define DEF_FLAT "0" +# define DEF_SPEED "0.05" +# define DEF_ROTATIONX "0.01" +# define DEF_ROTATIONY "0.0" +# define DEF_ROTATIONZ "0.1" +# define DEF_WAVES "3" +# define DEF_WAVE_CHANGE "50" +# define DEF_WAVE_HEIGHT "1.0" +# define DEF_WAVE_FREQ "3.0" +# define DEF_ZOOM "1.0" + + + static int _squares; /* grid size */ static int _resolution; /* wireframe resolution */ static int _flat; @@ -115,19 +132,19 @@ static XrmOptionDescRec opts[] = { static argtype vars[] = { - {&_squares, "squares", "Squares", "19", t_Int}, - {&_resolution, "resolution", "Resolution", "4", t_Int}, -/* {&_draw, "draw", "Draw", "2", t_Int},*/ - {&_flat, "flat", "Flat", "0", t_Int}, - {&_speed, "speed", "Speed", "0.05", t_Float}, - {&_rotationx, "rotationx", "Rotationx", "0.01", t_Float}, - {&_rotationy, "rotationy", "Rotationy", "0.0", t_Float}, - {&_rotationz, "rotationz", "Rotationz", "0.1", t_Float}, - {&_waves, "waves", "Waves", "3", t_Int}, - {&_waveChange, "waveChange", "WaveChange", "50", t_Int}, - {&_waveHeight, "waveHeight", "WaveHeight", "1.0", t_Float}, - {&_waveFreq, "waveFreq", "WaveFreq", "3.0", t_Float}, - {&_zoom, "zoom", "Zoom", "1.0", t_Float}, + {&_squares, "squares", "Squares", DEF_SQUARES, t_Int}, + {&_resolution, "resolution", "Resolution", DEF_RESOLUTION, t_Int}, +/* {&_draw, "draw", "Draw", DEF_DRAW, t_Int},*/ + {&_flat, "flat", "Flat", DEF_FLAT, t_Int}, + {&_speed, "speed", "Speed", DEF_SPEED, t_Float}, + {&_rotationx, "rotationx", "Rotationx", DEF_ROTATIONX, t_Float}, + {&_rotationy, "rotationy", "Rotationy", DEF_ROTATIONY, t_Float}, + {&_rotationz, "rotationz", "Rotationz", DEF_ROTATIONZ, t_Float}, + {&_waves, "waves", "Waves", DEF_WAVES, t_Int}, + {&_waveChange, "waveChange", "WaveChange", DEF_WAVE_CHANGE, t_Int}, + {&_waveHeight, "waveHeight", "WaveHeight", DEF_WAVE_HEIGHT, t_Float}, + {&_waveFreq, "waveFreq", "WaveFreq", DEF_WAVE_FREQ, t_Float}, + {&_zoom, "zoom", "Zoom", DEF_ZOOM, t_Float}, }; @@ -152,10 +169,10 @@ ENTRYPOINT ModeSpecOpt gflux_opts = {countof(opts), opts, countof(vars), vars, d #ifdef USE_MODULES ModStruct gflux_description = -{"gflux", "init_gflux", "draw_gflux", "release_gflux", +{"gflux", "init_gflux", "draw_gflux", NULL, "draw_gflux", "init_gflux", NULL, &gflux_opts, 1000, 1, 2, 1, 4, 1.0, "", - "Gflux: an OpenGL gflux", 0, NULL}; + "GFlux: an OpenGL gflux", 0, NULL}; #endif /* structure for holding the gflux data */ @@ -176,7 +193,7 @@ typedef struct gfluxstruct { GLfloat tex_yscale; XRectangle img_geom; int img_width, img_height; - void (*drawFunc)(struct gfluxstruct *); + int (*drawFunc)(struct gfluxstruct *); trackball_state *trackball; Bool button_down_p; @@ -199,10 +216,10 @@ static gfluxstruct *gfluxes = NULL; static void initLighting(void); static void grabTexture(gfluxstruct *); static void createTexture(gfluxstruct *); -static void displaySolid(gfluxstruct *); /* drawFunc implementations */ -static void displayLight(gfluxstruct *); -static void displayTexture(gfluxstruct *); -static void displayWire(gfluxstruct *); +static int displaySolid(gfluxstruct *); /* drawFunc implementations */ +static int displayLight(gfluxstruct *); +static int displayTexture(gfluxstruct *); +static int displayWire(gfluxstruct *); static void calcGrid(gfluxstruct *); static double getGrid(gfluxstruct *,double,double,double); @@ -224,38 +241,16 @@ gflux_handle_event (ModeInfo *mi, XEvent *event) { gfluxstruct *gp = &gfluxes[MI_SCREEN(mi)]; - if (event->xany.type == ButtonPress && - event->xbutton.button == Button1) + if (gltrackball_event_handler (event, gp->trackball, + MI_WIDTH (mi), MI_HEIGHT (mi), + &gp->button_down_p)) + return True; + else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event)) { - gp->button_down_p = True; - gltrackball_start (gp->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) - { - gp->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 (gp->trackball, event->xbutton.button, 10, - !!event->xbutton.state); - return True; - } - else if (event->xany.type == MotionNotify && - gp->button_down_p) - { - gltrackball_track (gp->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; + if (_draw == grab) { + grabTexture(gp); + return True; + } } return False; @@ -283,29 +278,32 @@ ENTRYPOINT void draw_gflux(ModeInfo * mi) glXMakeCurrent(display, window, *(gp->glx_context)); calcGrid(gp); - gp->drawFunc(gp); + mi->polygon_count = gp->drawFunc(gp); if (mi->fps_p) do_fps (mi); glXSwapBuffers(display, window); } -/* reset the projection matrix */ -static void resetProjection(void) +/* Standard reshape function */ +ENTRYPOINT void +reshape_gflux(ModeInfo *mi, int width, int height) { + glViewport( 0, 0, width, height ); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-_zoom,_zoom,-0.8*_zoom,0.8*_zoom,2,6); glTranslatef(0.0,0.0,-4.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); -} -/* Standard reshape function */ -ENTRYPOINT void -reshape_gflux(ModeInfo *mi, int width, int height) -{ - glViewport( 0, 0, width, height ); - resetProjection(); +# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ + { + GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi); + int o = (int) current_device_rotation(); + if (o != 0 && o != 180 && o != -180) + glScalef (1/h, 1/h, 1/h); + } +# endif } @@ -361,20 +359,16 @@ ENTRYPOINT void init_gflux(ModeInfo * mi) int screen = MI_SCREEN(mi); gfluxstruct *gp; - if (gfluxes == NULL) { - if ((gfluxes = (gfluxstruct *) - calloc(MI_NUM_SCREENS(mi), sizeof (gfluxstruct))) == NULL) - return; - } + MI_INIT(mi, gfluxes, NULL); gp = &gfluxes[screen]; - gp->trackball = gltrackball_init (); + gp->trackball = gltrackball_init (True); gp->time = frand(1000.0); /* don't run two screens in lockstep */ { char *s = get_string_resource (mi->dpy, "mode", "Mode"); - if (!s || !*s) _draw = wire; + if (!s || !*s) _draw = grab; else if (!strcasecmp (s, "wire")) _draw = wire; else if (!strcasecmp (s, "solid")) _draw = solid; else if (!strcasecmp (s, "light")) _draw = light; @@ -400,16 +394,6 @@ ENTRYPOINT void init_gflux(ModeInfo * mi) } } -/* cleanup code */ -ENTRYPOINT void release_gflux(ModeInfo * mi) -{ - if (gfluxes != NULL) { - free((void *) gfluxes); - gfluxes = NULL; - } - FreeAllGL(mi); -} - static void createTexture(gfluxstruct *gp) { @@ -507,8 +491,9 @@ static void initLighting(void) /* storing the values in an array */ /* is a posibility */ /************************************/ -static void displayTexture(gfluxstruct *gp) +static int displayTexture(gfluxstruct *gp) { + int polys = 0; double x,y,u,v; double z; double dx = 2.0/((double)_squares); @@ -587,6 +572,7 @@ static void displayTexture(gfluxstruct *gp) 1 ); glVertex3f(x+dx,y,z); + polys++; } glEnd(); } @@ -599,18 +585,25 @@ static void displayTexture(gfluxstruct *gp) glBegin(GL_LINE_LOOP); y = miny; - for (x = minx; x <= maxx; x += dx) + for (x = minx; x <= maxx; x += dx) { glVertex3f (x, y, getGrid (gp, x, y, gp->time)); + polys++; + } x = maxx; - for (y = miny; y <= maxy; y += dy) + for (y = miny; y <= maxy; y += dy) { glVertex3f (x, y, getGrid (gp, x, y, gp->time)); + polys++; + } y = maxy; - for (x = maxx; x >= minx; x -= dx) + for (x = maxx; x >= minx; x -= dx) { glVertex3f (x, y, getGrid (gp, x, y, gp->time)); + polys++; + } x = minx; - for (y = maxy; y >= miny; y -= dy) + for (y = maxy; y >= miny; y -= dy) { glVertex3f (x, y, getGrid (gp, x, y, gp->time)); - + polys++; + } glEnd(); glEnable(GL_TEXTURE_2D); @@ -620,9 +613,12 @@ static void displayTexture(gfluxstruct *gp) gp->angley -= _rotationy; gp->anglez -= _rotationz; } + return polys; } -static void displaySolid(gfluxstruct *gp) + +static int displaySolid(gfluxstruct *gp) { + int polys = 0; double x,y; double z; double dx = 2.0/((double)_squares); @@ -648,6 +644,7 @@ static void displaySolid(gfluxstruct *gp) genColour(z); glColor3fv(gp->colour); glVertex3f(x+dx,y,z); + polys++; } glEnd(); } @@ -659,10 +656,12 @@ static void displaySolid(gfluxstruct *gp) gp->anglez -= _rotationz; } + return polys; } -static void displayLight(gfluxstruct *gp) +static int displayLight(gfluxstruct *gp) { + int polys = 0; double x,y; double z; double dx = 2.0/((double)_squares); @@ -698,6 +697,7 @@ static void displayLight(gfluxstruct *gp) 1 ); glVertex3f(x+dx,y,z); + polys++; } glEnd(); } @@ -708,10 +708,12 @@ static void displayLight(gfluxstruct *gp) gp->angley -= _rotationy; gp->anglez -= _rotationz; } + return polys; } -static void displayWire(gfluxstruct *gp) +static int displayWire(gfluxstruct *gp) { + int polys = 0; double x,y; double z; double dx1 = 2.0/((double)(_squares*_resolution)) - 0.00001; @@ -734,6 +736,7 @@ static void displayWire(gfluxstruct *gp) genColour(z); glColor3fv(gp->colour); glVertex3f(x,y,z); + polys++; } glEnd(); } @@ -744,6 +747,7 @@ static void displayWire(gfluxstruct *gp) genColour(z); glColor3fv(gp->colour); glVertex3f(x,y,z); + polys++; } glEnd(); } @@ -754,6 +758,7 @@ static void displayWire(gfluxstruct *gp) gp->angley -= _rotationy; gp->anglez -= _rotationz; } + return polys; } /* generates new ripples */ @@ -793,6 +798,6 @@ static double getGrid(gfluxstruct *gp, double x, double y, double a) } -XSCREENSAVER_MODULE ("Gflux", gflux) +XSCREENSAVER_MODULE ("GFlux", gflux) #endif