*
* 2007: Written by Matthias Toussaint
* 0.1 Initial version
- * 0.2 Bugfixes (threading) and code cleanup by Jamie Zavinsky
+ * 0.2 Bugfixes (threading) and code cleanup by Jamie Zawinski
* Window scaling bug + performance bug in tick()
*/
#define INDEX_OFFSET 100000
#define NUM_CELL_SHAPES 10
-#define refresh_glcells 0
-#define glcells_handle_event 0
+#define release_glcells 0
+#define glcells_handle_event xlockmore_no_events
#define DEF_DELAY "20000"
#define DEF_MAXCELLS "800"
#define DEF_MINFOOD "5"
#define DEF_MAXFOOD "20"
#define DEF_DIVIDEAGE "20"
-#define DEF_MINDIST "1.40"
+#define DEF_MINDIST "1.4"
#define DEF_PAUSE "50"
#define DEFAULTS "*delay: 30000 \n" \
"*showFPS: False \n" \
"*wireframe: False \n" \
+ "*suppressRotationAnimation: True\n" \
#undef countof
#define countof(x) (sizeof((x))/sizeof((*x)))
-#define USE_VERTEX_ARRAY
+#ifndef HAVE_JWZGLES /* glDrawElements unimplemented... */
+# define USE_VERTEX_ARRAY
+#endif
#define TEX_SIZE 64
{&s_maxfood, "maxfood", "Max Food", DEF_MAXFOOD, t_Int},
{&s_pause, "pause", "Pause at end", DEF_PAUSE, t_Int},
{&s_divideage, "divideage", "Age for duplication (Ticks)", DEF_DIVIDEAGE, t_Int},
- {&s_min_dist, "mindist", "Minimum prefered distance to other cells", DEF_MINDIST, t_Float},
+ {&s_min_dist, "mindist", "Minimum preferred distance to other cells", DEF_MINDIST, t_Float},
{&s_keepold, "keepold", "Keep old cells", DEF_KEEPOLD, t_Bool}
};
static Object *clone_Object( Object * );
/* return 1 if cell is capable to divide */
static int can_divide( State *st, Cell *cell );
+#ifdef USE_VERTEX_ARRAY
static VertexArray *array_from_ObjectSmooth( ObjectSmooth * );
+#endif
static void create_nucleus_texture( State *st );
ENTRYPOINT ModeSpecOpt glcells_opts = { countof(opts), opts, countof(vars), vars,
return ret;
}
+#ifdef USE_VERTEX_ARRAY
static VertexArray *array_from_ObjectSmooth( ObjectSmooth *obj )
{
int i, j;
return array;
}
+#endif /* USE_VERTEX_ARRAY */
+
/* create a smoothed version of the given Object
by computing average normal vectors for the vertexes
fprintf( stderr, "tick %d\n", usec );
gettimeofday( &tv1, NULL );
#endif
- glClearColor( 0, 0, 0, 0 );
-
+
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glEnable( GL_NORMALIZE );
glPolygonMode( GL_FRONT, GL_FILL );
} else {
+# ifndef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */
glPolygonMode( GL_FRONT, GL_LINE );
+# endif
}
+# if 0
+ if (st->wire) {
+ glDisable(GL_DEPTH_TEST);
+ glColor3f (1, 1, 1);
+ glBegin(GL_LINE_LOOP);
+ glVertex3f(0, 0, 0); glVertex3f(st->width, 0, 0);
+ glVertex3f(st->width, st->height, 0); glVertex3f(0, st->height, 0);
+ glVertex3f(0, 0, 0); glVertex3f(st->width/4, 0, 0);
+ glVertex3f(st->width/4, st->height/4, 0); glVertex3f(0, st->height/4, 0);
+ glEnd();
+ }
+# endif
+
/* draw the dead cells if choosen */
if (st->keep_old_cells) {
for (b=0; b<st->num_cells; ++b) {
num_paint++;
/*glColor3f( fac, fac, fac );*/
+# if 0
+ if (st->wire) {
+ glBegin(GL_LINES);
+ glVertex3f(0, 0, 0);
+ glVertex3f(st->cell[b].x, st->cell[b].y, 0);
+ glEnd();
+ }
+# endif
+
glPushMatrix();
glTranslatef( st->cell[b].x, st->cell[b].y, 0.0 );
glRotatef( st->cell[b].rotation, 0.0, 0.0, 1.0 );
ObjectSmooth *smooth;
#ifdef USE_VERTEX_ARRAY
VertexArray *vertex_array;
+#else
+ int t, i;
#endif
int list = glGenLists(1);
static void draw_cell( State *st, int shape )
{
+# ifdef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */
+ if (st->wire) {
+ glDisable(GL_DEPTH_TEST);
+ glColor3f (1, 1, 1);
+ glPushMatrix();
+ glScalef (0.33, 0.33, 1);
+ glBegin (GL_LINE_LOOP);
+ glVertex3f (-1, -1, 0); glVertex3f (-1, 1, 0);
+ glVertex3f ( 1, 1, 0); glVertex3f ( 1, -1, 0);
+ glEnd();
+ if (shape == 9) {
+ glBegin (GL_LINES);
+ glVertex3f (-1, -1, 0); glVertex3f (1, 1, 0);
+ glVertex3f (-1, 1, 0); glVertex3f (1, -1, 0);
+ glEnd();
+ }
+ glPopMatrix();
+ return;
+ }
+# endif
+
if (-1 == st->cell_list[shape]) {
st->cell_list[shape] = create_list( st, (double)shape/10.0 );
}
/* have a snack */
x = ((int)st->cell[b].x)/4;
- if (x<0) x=0; if (x>=w4) x = w4-1;
+ if (x<0) x=0;
+ if (x>=w4) x = w4-1;
y = ((int)st->cell[b].y)/4;
- if (y<0) y=0; if (y>=h4) y = h4-1;
+ if (y<0) y=0;
+ if (y>=h4) y = h4-1;
offset = x+y*w4;
reshape_glcells( ModeInfo *mi, int width, int height )
{
State *st = &sstate[MI_SCREEN(mi)];
+# ifdef HAVE_MOBILE
+ int rot = current_device_rotation();
+# endif
st->height = height;
st->width = width;
+# ifdef HAVE_MOBILE
+ st->screen_scale = (double)(width < height ? width : height) / 1600.0;
+# else
st->screen_scale = (double)width / 1600.0;
-
+# endif
+
st->radius = s_radius;
if (st->radius < 5) st->radius = 5;
if (st->radius > 200) st->radius = 200;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho( 0, width, height, 0, 200, 0 );
+# ifdef HAVE_MOBILE
+ glRotatef (rot, 0, 0, 1);
+# endif
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
-
if (st->food) free( st->food );
st->food = (int *)malloc( ((width*height)/16)*sizeof(int) );
-
- create_cells( st );
+ /* create_cells( st );*/
+
+# ifdef HAVE_MOBILE
+ glTranslatef (st->width/2, st->height/2, 0);
+ if (rot == 90 || rot == -90 || rot == 270 || rot == -270)
+ st->width = height, st->height = width;
+ glRotatef (rot, 0, 0, 1);
+ if (st->wire) glScalef(0.8, 0.8, 1);
+ glTranslatef (-st->width/2, -st->height/2, 0);
+# endif
}
ENTRYPOINT void
int i, divisions;
State *st=0;
- if (!sstate) {
- sstate = (State *)
- calloc( MI_NUM_SCREENS(mi), sizeof(State) );
- if (!sstate) {
- fprintf( stderr, "%s: out of memory\n", progname );
- exit(1);
- }
- }
+ MI_INIT(mi, sstate);
st = &sstate[MI_SCREEN(mi)];
st->glx_context = init_GL(mi);
*(st->glx_context) );
mi->polygon_count = render( st );
-
+
if (mi->fps_p) do_fps (mi);
glFinish();
}
ENTRYPOINT void
-release_glcells( ModeInfo *mi )
+free_glcells( ModeInfo *mi )
{
int i;
State *st = &sstate[MI_SCREEN(mi)];
+
+ if (st->glx_context) {
+ glXMakeCurrent( MI_DISPLAY(mi), MI_WINDOW(mi),
+ *(st->glx_context) );
- /* nuke everything before exit */
- if (st->sphere) free_Object( st->sphere );
- if (st->food) free( st->food );
- for (i=0; i<NUM_CELL_SHAPES; ++i) {
- if (st->cell_list[i] != -1) {
- glDeleteLists( st->cell_list[i], 1 );
+ /* nuke everything before exit */
+ if (st->sphere) free_Object( st->sphere );
+ if (st->food) free( st->food );
+ for (i=0; i<NUM_CELL_SHAPES; ++i) {
+ if (st->cell_list[i] != -1) {
+ glDeleteLists( st->cell_list[i], 1 );
+ }
}
+ if (st->cell) free( st->cell );
+ free( st->disturbance );
+ glDeleteTextures( 1, &st->texture_name );
+ free( st->texture );
}
- if (st->cell) free( st->cell );
- free( st->disturbance );
- glDeleteTextures( 1, &st->texture_name );
- free( st->texture );
}
XSCREENSAVER_MODULE( "GLCells", glcells )