#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 */
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;
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},
};
#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 */
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;
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);
{
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;
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
}
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;
}
}
-/* cleanup code */
-ENTRYPOINT void release_gflux(ModeInfo * mi)
-{
- if (gfluxes != NULL) {
- free((void *) gfluxes);
- gfluxes = NULL;
- }
- FreeAllGL(mi);
-}
-
static void createTexture(gfluxstruct *gp)
{
/* 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);
1
);
glVertex3f(x+dx,y,z);
+ polys++;
}
glEnd();
}
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);
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);
genColour(z);
glColor3fv(gp->colour);
glVertex3f(x+dx,y,z);
+ polys++;
}
glEnd();
}
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);
1
);
glVertex3f(x+dx,y,z);
+ polys++;
}
glEnd();
}
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;
genColour(z);
glColor3fv(gp->colour);
glVertex3f(x,y,z);
+ polys++;
}
glEnd();
}
genColour(z);
glColor3fv(gp->colour);
glVertex3f(x,y,z);
+ polys++;
}
glEnd();
}
gp->angley -= _rotationy;
gp->anglez -= _rotationz;
}
+ return polys;
}
/* generates new ripples */
}
-XSCREENSAVER_MODULE ("Gflux", gflux)
+XSCREENSAVER_MODULE ("GFlux", gflux)
#endif