*
*/
-#include <X11/Intrinsic.h>
-
#ifdef STANDALONE
-# define PROGCLASS "Jigglypuff"
-# define HACK_INIT init_jigglypuff
-# define HACK_DRAW draw_jigglypuff
-# define HACK_RESHAPE reshape_jigglypuff
-# define HACK_HANDLE_EVENT jigglypuff_handle_event
-# define EVENT_MASK PointerMotionMask
-# define jigglypuff_opts xlockmore_opts
-
-#define DEF_COLOR "cycle"
-#define DEF_SHININESS "100"
-#define DEF_COMPLEXITY "2"
-#define DEF_SPEED "500"
-#define DEF_DISTANCE "100"
-#define DEF_HOLD "800"
-#define DEF_SPHERISM "75"
-#define DEF_DAMPING "500"
-
# define DEFAULTS "*delay: 20000\n" \
"*showFPS: False\n" \
"*wireframe: False\n" \
- "*color: cycle\n" \
- "*shininess: 100\n" \
- "*complexity: 2\n" \
- "*speed: 500\n" \
- "*distance: 100\n" \
- "*hold: 800\n" \
- "*spherism: 200\n" \
- "*damping: 500\n"
-
+ "*suppressRotationAnimation: True\n" \
+# define free_jigglypuff 0
+# define release_jigglypuff 0
# include "xlockmore.h"
#else
# include "xlock.h"
# include "config.h"
#endif
-#include "xpm-ximage.h"
+#include "ximage-loader.h"
#include "gltrackball.h"
-#include "../images/jigglymap.xpm"
+#include "images/gen/jigglymap_png.h"
#ifdef USE_GL
-#include <GL/gl.h>
+
+
+#define DEF_COLOR "cycle"
+#define DEF_SHININESS "100"
+#define DEF_COMPLEXITY "2"
+#define DEF_SPEED "500"
+#define DEF_DISTANCE "100"
+#define DEF_HOLD "800"
+#define DEF_SPHERISM "75"
+#define DEF_DAMPING "500"
+#define DEF_RANDOM "True"
+#define DEF_TETRA "False"
+#define DEF_SPOOKY "0"
#ifndef max
#define max(a,b) (((a)>(b))?(a):(b))
static jigglystruct *jss = NULL;
static XrmOptionDescRec opts[] = {
- {"-random", ".Jigglypuff.random", XrmoptionNoArg, (caddr_t)"true"},
- {"+random", ".Jigglypuff.random", XrmoptionNoArg, (caddr_t)"false"},
- {"-tetra", ".Jigglypuff.tetra", XrmoptionNoArg, (caddr_t)"true"},
- {"+tetra", ".Jigglypuff.tetra", XrmoptionNoArg, (caddr_t)"false"},
- {"-spooky", ".Jigglypuff.spooky", XrmoptionSepArg, (caddr_t)"0"},
- {"-color", ".Jigglypuff.color", XrmoptionSepArg, (caddr_t)DEF_COLOR},
- {"-shininess", ".Jigglypuff.shininess", XrmoptionSepArg, (caddr_t)DEF_SHININESS},
- {"-complexity", ".Jigglypuff.complexity", XrmoptionSepArg, (caddr_t)DEF_COMPLEXITY},
- {"-speed", ".Jigglypuff.speed", XrmoptionSepArg, (caddr_t)DEF_SPEED},
- {"-spherism", ".Jigglypuff.spherism", XrmoptionSepArg, (caddr_t)DEF_SPHERISM},
- {"-hold", ".Jigglypuff.hold", XrmoptionSepArg, (caddr_t)DEF_HOLD},
- {"-distance", "Jigglypuff.distance", XrmoptionSepArg, (caddr_t)DEF_DISTANCE},
- {"-damping", "Jigglypuff.damping", XrmoptionSepArg, (caddr_t)DEF_DAMPING}
+ {"-random", ".Jigglypuff.random", XrmoptionNoArg, "true"},
+ {"+random", ".Jigglypuff.random", XrmoptionNoArg, "false"},
+ {"-tetra", ".Jigglypuff.tetra", XrmoptionNoArg, "true"},
+ {"+tetra", ".Jigglypuff.tetra", XrmoptionNoArg, "false"},
+ {"-spooky", ".Jigglypuff.spooky", XrmoptionSepArg, "0"},
+ {"-color", ".Jigglypuff.color", XrmoptionSepArg, DEF_COLOR},
+ {"-shininess", ".Jigglypuff.shininess", XrmoptionSepArg, DEF_SHININESS},
+ {"-complexity", ".Jigglypuff.complexity", XrmoptionSepArg, DEF_COMPLEXITY},
+ {"-speed", ".Jigglypuff.speed", XrmoptionSepArg, DEF_SPEED},
+ {"-spherism", ".Jigglypuff.spherism", XrmoptionSepArg, DEF_SPHERISM},
+ {"-hold", ".Jigglypuff.hold", XrmoptionSepArg, DEF_HOLD},
+ {"-distance", "Jigglypuff.distance", XrmoptionSepArg, DEF_DISTANCE},
+ {"-damping", "Jigglypuff.damping", XrmoptionSepArg, DEF_DAMPING}
};
static argtype vars[] = {
- {(caddr_t*)&random_parms, "random", "Random", "False", t_Bool},
- {(caddr_t*)&do_tetrahedron, "tetra", "Tetra", "False", t_Bool},
- {(caddr_t*)&spooky, "spooky", "Spooky", "0", t_Int},
- {(caddr_t*)&color, "color", "Color", DEF_COLOR, t_String},
- {(caddr_t*)&shininess, "shininess", "Shininess", DEF_SHININESS, t_Int},
- {(caddr_t*)&complexity, "complexity", "Complexity", DEF_COMPLEXITY, t_Int},
- {(caddr_t*)&speed, "speed", "Speed", DEF_SPEED, t_Int},
- {(caddr_t*)&spherism, "spherism", "Spherism", DEF_SPHERISM, t_Int},
- {(caddr_t*)&hold, "hold", "Hold", DEF_HOLD, t_Int},
- {(caddr_t*)&distance, "distance", "Distance", DEF_DISTANCE, t_Int},
- {(caddr_t*)&damping, "damping", "Damping", DEF_DAMPING, t_Int}
+ {&random_parms, "random", "Random", DEF_RANDOM, t_Bool},
+ {&do_tetrahedron, "tetra", "Tetra", DEF_TETRA, t_Bool},
+ {&spooky, "spooky", "Spooky", DEF_SPOOKY, t_Int},
+ {&color, "color", "Color", DEF_COLOR, t_String},
+ {&shininess, "shininess", "Shininess", DEF_SHININESS, t_Int},
+ {&complexity, "complexity", "Complexity", DEF_COMPLEXITY, t_Int},
+ {&speed, "speed", "Speed", DEF_SPEED, t_Int},
+ {&spherism, "spherism", "Spherism", DEF_SPHERISM, t_Int},
+ {&hold, "hold", "Hold", DEF_HOLD, t_Int},
+ {&distance, "distance", "Distance", DEF_DISTANCE, t_Int},
+ {&damping, "damping", "Damping", DEF_DAMPING, t_Int}
};
#undef countof
#define countof(x) ((int)(sizeof(x)/sizeof(*(x))))
-ModeSpecOpt jigglypuff_opts = {countof(opts), opts, countof(vars), vars, NULL};
+ENTRYPOINT ModeSpecOpt jigglypuff_opts = {countof(opts), opts, countof(vars), vars, NULL};
#define COLOR_STYLE_NORMAL 0
#define COLOR_STYLE_CYCLE 1
#define CLOWNBARF_NCOLORS 5
-static GLfloat clownbarf_colors[CLOWNBARF_NCOLORS][4] = {
+static const GLfloat clownbarf_colors[CLOWNBARF_NCOLORS][4] = {
{0.7, 0.7, 0.0, 1.0},
{0.8, 0.1, 0.1, 1.0},
{0.1, 0.1, 0.8, 1.0},
{0.0, 0.0, 0.0, 1.0}
};
-static GLfloat flowerbox_colors[4][4] = {
+static const GLfloat flowerbox_colors[4][4] = {
{0.7, 0.7, 0.0, 1.0},
{0.9, 0.0, 0.0, 1.0},
{0.0, 0.9, 0.0, 1.0},
{0.0, 0.0, 0.9, 1.0},
};
+# if 0 /* I am not even going to *try* and make this bullshit compile
+ without warning under gcc -std=c89 -pedantic. -jwz. */
#ifdef DEBUG
+# ifdef __GNUC__ /* GCC style */
#define _DEBUG(msg, args...) do { \
fprintf(stderr, "%s : %d : " msg ,__FILE__,__LINE__ ,##args); \
} while(0)
+# else /* C99 standard style */
+#define _DEBUG(msg, ...) do { \
+ fprintf(stderr, "%s : %d : " msg ,__FILE__,__LINE__,__VA_ARGS__); \
+} while(0)
+# endif
#else
+# ifdef __GNUC__ /* GCC style */
#define _DEBUG(msg, args...)
+# else /* C99 standard style */
+#define _DEBUG(msg, ...)
+# endif
#endif
+#endif /* 0 */
/* This is all the half-edge b-rep code (as well as basic geometry) */
typedef struct face face;
struct face {
solid *s;
hedge *start;
- GLfloat *color;
+ const GLfloat *color;
face *next;
};
v[2] *= s;
}
+/*
static inline coord dot(vector v1, vector v2)
{
return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
}
+*/
static inline void cross(vector v1, vector v2, vector v)
{
return h->e->left;
}
else {
- _DEBUG("Inconsistent edge detected. Presumably, this is a bug. Exiting.\n");
+/* _DEBUG("Inconsistent edge detected. Presumably, this is a bug. Exiting.\n", NULL); */
exit(-1);
}
}
-vertex *vertex_new(solid *s, vector v)
+static vertex *vertex_new(solid *s, vector v)
{
vertex *vtx = (vertex*)malloc(sizeof(vertex));
* i.e. it is a helper for the split_* functions, which
* maintain the consistency of the solid.
*/
-hedge *hedge_new(hedge *hafter, vertex *vtx)
+static hedge *hedge_new(hedge *hafter, vertex *vtx)
{
hedge *h = (hedge*)malloc(sizeof(hedge));
if(!h) {
- _DEBUG("Out of memory in hedge_new()\n");
+/* _DEBUG("Out of memory in hedge_new()\n",NULL); */
return NULL;
}
h->f = hafter->f;
return h;
}
-edge *edge_new(solid *s)
+static edge *edge_new(solid *s)
{
edge *e = (edge*)malloc(sizeof(edge));
if(!e) {
- _DEBUG("Out of memory in edge_new()\n");
+/* _DEBUG("Out of memory in edge_new()\n",NULL);*/
exit(-1);
}
e->next = s->edges;
return e;
}
-face *face_new(solid *s, hedge *h)
+static face *face_new(solid *s, hedge *h)
{
face *f = (face*)malloc(sizeof(face));
if(!f) {
- _DEBUG("Out of memory in face_new()");
+/* _DEBUG("Out of memory in face_new()",NULL);*/
exit(-1);
}
f->s = s;
* the vertex returned will have h==<the new halfedge>.
*/
-vertex *vertex_split(hedge *h, vector v)
+static vertex *vertex_split(hedge *h, vector v)
{
hedge *h2, *hn1, *hn2;
vertex *vtxn;
edge *en;
- face *f1, *f2;
+ face *f1;
f1 = h->f;
h2 = partner(h);
- f2 = h2->f;
vtxn = vertex_new(f1->s, v);
hn1 = hedge_new(h, vtxn);
return vtxn;
}
-face *face_split(face *f, hedge *h1, hedge *h2)
+static face *face_split(face *f, hedge *h1, hedge *h2)
{
hedge *hn1, *hn2, *tmp;
edge *en;
face *fn;
if(h1->f != f || h2->f != f) {
- _DEBUG("Whoah, cap'n, yer usin' a bad halfedge!\n");
+/* _DEBUG("Whoah, cap'n, yer usin' a bad halfedge!\n",NULL);*/
exit(-1);
}
if(h1 == h2) {
- _DEBUG("Trying to split a face at a single vertex\n");
+/* _DEBUG("Trying to split a face at a single vertex\n",NULL);*/
exit(-1);
}
/* close the loops */
return fn;
}
-solid *solid_new(vector where)
+static solid *solid_new(vector where)
{
solid *s = (solid*)malloc(sizeof(solid));
face *f1, *f2;
}
/* This is all the code directly related to constructing the jigglypuff */
-void face_tessel2(face *f)
+static void face_tessel2(face *f)
{
hedge *h1=f->start->prev, *h2=f->start->next;
* added at the head of the list. If that ever changes,
* this is borked.
*/
-void solid_tesselate(solid *s)
+static void solid_tesselate(solid *s)
{
edge *e = s->edges;
face *f = s->faces;
}
}
-void solid_spherify(solid * s, coord size)
+static void solid_spherify(solid * s, coord size)
{
vertex *vtx = s->vertices;
}
}
-solid *tetrahedron(jigglystruct *js)
+static solid *tetrahedron(jigglystruct *js)
{
solid *s;
vertex *vtx;
return s;
}
-solid *tesselated_tetrahedron(coord size, int iter, jigglystruct *js) {
+static solid *tesselated_tetrahedron(coord size, int iter, jigglystruct *js) {
solid *s = tetrahedron(js);
int i;
* see what the cost is of calling glBegin/glEnd for each
* triangle.
*/
-static inline void face_render(face *f, jigglystruct *js)
+static inline int face_render(face *f, jigglystruct *js)
{
hedge *h1, *h2, *hend;
+ int polys = 0;
h1 = f->start;
hend = h1->prev;
vertex_render(hend->vtx, js);
h1 = h2;
h2 = h1->next;
+ polys++;
}
glEnd();
+ return polys;
}
-void jigglypuff_render(jigglystruct *js)
+static int jigglypuff_render(jigglystruct *js)
{
+ int polys = 0;
face *f = js->shape->faces;
vertex *vtx = js->shape->vertices;
vtx = vtx->next;
}
while(f) {
- face_render(f, js);
+ polys += face_render(f, js);
f=f->next;
}
+ return polys;
}
/* This is the jiggling code */
/* stable distance when subdivs == 4 */
#define STABLE_DISTANCE 0.088388347648
-void update_shape(jigglystruct *js)
+static void update_shape(jigglystruct *js)
{
vertex *vtx = js->shape->vertices;
edge *e = js->shape->edges;
/* These are the various initialization routines */
-void init_texture(ModeInfo *mi)
+static void init_texture(ModeInfo *mi)
{
- XImage *img = xpm_to_ximage(mi->dpy, mi->xgwa.visual,
- mi->xgwa.colormap, jigglymap_xpm);
+ XImage *img = image_data_to_ximage(mi->dpy, mi->xgwa.visual,
+ jigglymap_png, sizeof(jigglymap_png));
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
img->width, img->height, 0, GL_RGBA,
XDestroyImage(img);
}
-void setup_opengl(ModeInfo *mi, jigglystruct *js)
+static void setup_opengl(ModeInfo *mi, jigglystruct *js)
{
const GLfloat lpos0[4] = {-12, 8, 12, 0};
const GLfloat lpos1[4] = {7, -5, 0, 0};
- const GLfloat lcol0[4] = {0.7, 0.7, 0.65, 1};
- const GLfloat lcol1[4] = {0.3, 0.2, 0.1, 1};
- const GLfloat scolor[4]= {0.9, 0.9, 0.9, 0.5};
+ const GLfloat lcol0[4] = {0.7f, 0.7f, 0.65f, 1};
+ const GLfloat lcol1[4] = {0.3f, 0.2f, 0.1f, 1};
+ const GLfloat scolor[4]= {0.9f, 0.9f, 0.9f, 0.5f};
glDrawBuffer(GL_BACK);
- glClearColor(0, 0, 0, 0);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
}
}
-int parse_color(jigglystruct *js)
+static int parse_color(jigglystruct *js)
{
- int r, g, b;
+ unsigned int r, g, b;
if(!strcmp(color, "clownbarf")) {
js->color_style = COLOR_STYLE_CLOWNBARF;
return 1;
js->color_style = COLOR_STYLE_FLOWERBOX;
return 1;
}
+# ifndef HAVE_JWZGLES /* SPHERE_MAP unimplemented */
else if(!strcmp(color, "chrome")) {
js->color_style = COLOR_STYLE_CHROME;
return 1;
}
+# endif
else if(!strcmp(color, "cycle")) {
js->color_style = COLOR_STYLE_CYCLE;
js->jiggly_color[0] = ((float)random()) / REAL_RAND_MAX * 0.7 + 0.3;
return 1;
}
-void randomize_parameters(jigglystruct *js) {
+static void randomize_parameters(jigglystruct *js) {
do_tetrahedron = random() & 1;
+# ifndef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */
js->do_wireframe = !(random() & 3);
+# endif
js->color_style = random() % 5;
+# ifdef HAVE_JWZGLES /* #### SPHERE_MAP unimplemented */
+ while (js->color_style == COLOR_STYLE_CHROME)
+ js->color_style = random() % 5;;
+# endif
if(js->color_style == COLOR_STYLE_NORMAL
|| js->color_style == COLOR_STYLE_CYCLE) {
js->jiggly_color[0] = ((float)random()) / REAL_RAND_MAX * 0.5 + 0.5;
damping = (random() % 800) + 50;
}
-void calculate_parameters(jigglystruct *js, int subdivs) {
+static void calculate_parameters(jigglystruct *js, int subdivs) {
/* try to compensate for the inherent instability at
* low complexity. */
float dist_factor = (subdivs == 6) ? 2 : (subdivs == 5) ? 1 : 0.5;
/* The screenhack related functions begin here */
-Bool jigglypuff_handle_event(ModeInfo *mi, XEvent *event)
+ENTRYPOINT Bool jigglypuff_handle_event(ModeInfo *mi, XEvent *event)
{
jigglystruct *js = &jss[MI_SCREEN(mi)];
- if(event->xany.type == ButtonPress &&
- event->xbutton.button & Button1) {
- js->button_down = 1;
- gltrackball_start(js->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) {
- js->button_down = 0;
- return True;
- }
- else if(event->xany.type == MotionNotify && js->button_down) {
- gltrackball_track(js->trackball, event->xmotion.x, event->xmotion.y,
- MI_WIDTH(mi), MI_HEIGHT(mi));
- return True;
- }
+ if (gltrackball_event_handler (event, js->trackball,
+ MI_WIDTH (mi), MI_HEIGHT (mi),
+ &js->button_down))
+ return True;
+
return False;
}
-void reshape_jigglypuff(ModeInfo *mi, int width, int height)
+ENTRYPOINT void reshape_jigglypuff(ModeInfo *mi, int width, int height)
{
- GLfloat aspect = (GLfloat)width / (GLfloat)height;
-
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(-0.5*aspect, 0.5*aspect, -0.5, 0.5, 1, 20);
-/* glTranslatef(0, 0, -10);*/
+ double h = (GLfloat) height / (GLfloat) width;
+ int y = 0;
+
+ if (width > height * 5) { /* tiny window: show middle */
+ height = width * 9/16;
+ y = -height/2;
+ h = height / (GLfloat) width;
+ }
+
+ glViewport(0, y, width, height);
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-0.5*(1/h), 0.5*(1/h), -0.5, 0.5, 1, 20);
}
-void draw_jigglypuff(ModeInfo *mi)
+ENTRYPOINT void draw_jigglypuff(ModeInfo *mi)
{
jigglystruct *js = &jss[MI_SCREEN(mi)];
glLoadIdentity();
glTranslatef(0,0,-10);
+
+# 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
+
glRotatef(js->angle, sin(js->axis), cos(js->axis), -sin(js->axis));
glTranslatef(0, 0, 5);
if(!(js->button_down)) {
js->axis -= 2*M_PI;
}
}
+
gltrackball_rotate(js->trackball);
if(js->color_style == COLOR_STYLE_CYCLE) {
glColor4fv(js->jiggly_color);
}
- jigglypuff_render(js);
+ mi->polygon_count = jigglypuff_render(js);
if(MI_IS_FPS(mi))
do_fps(mi);
glFinish();
glXSwapBuffers(MI_DISPLAY(mi), MI_WINDOW(mi));
}
-void init_jigglypuff(ModeInfo *mi)
+ENTRYPOINT void init_jigglypuff(ModeInfo *mi)
{
jigglystruct *js;
int subdivs;
- if(!jss) {
- jss = (jigglystruct*)
- calloc(MI_NUM_SCREENS(mi), sizeof(jigglystruct));
- if(!jss) {
- fprintf(stderr, "%s: No..memory...must...abort..\n", progname);
- exit(1);
- }
- }
+ MI_INIT(mi, jss);
js = &jss[MI_SCREEN(mi)];
js->do_wireframe = MI_IS_WIREFRAME(mi);
+# ifdef HAVE_JWZGLES
+ js->do_wireframe = 0; /* GL_LINE unimplemented */
+# endif
js->shininess = shininess;
if(random_parms)
randomize_parameters(js);
+ js->angle = frand(180);
+ js->axis = frand(M_PI);
+
js->shape = tesselated_tetrahedron(1, subdivs, js);
if(!do_tetrahedron)
else {
MI_CLEARWINDOW(mi);
}
- js->trackball = gltrackball_init();
- _DEBUG("distance : %f\nhold : %f\nspherify : %f\ndamping : %f\ndfact : %f\n",
+ js->trackball = gltrackball_init(True);
+/* _DEBUG("distance : %f\nhold : %f\nspherify : %f\ndamping : %f\ndfact : %f\n",
js->stable_distance, js->hold_strength, js->spherify_strength,
js->damping_velocity, js->damping_factor);
_DEBUG("wire : %d\nspooky : %d\nstyle : %d\nshininess : %d\n",
- js->do_wireframe, js->spooky, js->color_style, js->shininess);
+ js->do_wireframe, js->spooky, js->color_style, js->shininess);*/
}
-/* This is the end of the file */
+XSCREENSAVER_MODULE ("JigglyPuff", jigglypuff)
#endif /* USE_GL */
-
-
-
-
-
-
+/* This is the end of the file */