X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fvoronoi.c;h=895f96716fdc17b3c338f59976781105e1a28638;hb=78add6e627ee5f10e1fa6f3852602ea5066eee5a;hp=c59e6ba81bfd01e0ebf9d52430598bebe4b31f6f;hpb=c8c6deae79b408cffbc88043c766b3bc12cf0f13;p=xscreensaver diff --git a/hacks/glx/voronoi.c b/hacks/glx/voronoi.c index c59e6ba8..895f9671 100644 --- a/hacks/glx/voronoi.c +++ b/hacks/glx/voronoi.c @@ -1,4 +1,4 @@ -/* voronoi, Copyright (c) 2007 Jamie Zawinski +/* voronoi, Copyright (c) 2007-2018 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -11,9 +11,9 @@ #define DEFAULTS "*delay: 20000 \n" \ "*showFPS: False \n" \ + "*suppressRotationAnimation: True\n" \ - -# define refresh_voronoi 0 +# define free_voronoi 0 # define release_voronoi 0 #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) @@ -26,12 +26,12 @@ #ifdef USE_GL /* whole file */ -#define DEF_POINTS "10" +#define DEF_POINTS "25" #define DEF_POINT_SIZE "9" -#define DEF_POINT_SPEED "1" -#define DEF_POINT_DELAY "0.1" -#define DEF_ZOOM_SPEED "1" -#define DEF_ZOOM_DELAY "10" +#define DEF_POINT_SPEED "1.0" +#define DEF_POINT_DELAY "0.05" +#define DEF_ZOOM_SPEED "1.0" +#define DEF_ZOOM_DELAY "15" typedef struct node { GLfloat x, y; @@ -49,6 +49,7 @@ typedef struct { node *dragging; int ncolors; XColor *colors; + int point_size; enum { MODE_WAITING, MODE_ADDING, MODE_ZOOMING } mode; int adding; @@ -142,31 +143,20 @@ cone (void) int i; int faces = 64; GLfloat step = M_PI * 2 / faces; - GLfloat s2 = step/2; - GLfloat th; - GLfloat x, y, x0, y0; - - glBegin(GL_TRIANGLES); - - th = 0; - x = 1; - y = 0; - x0 = cos (s2); - y0 = sin (s2); + GLfloat th = 0; + GLfloat x = 1; + GLfloat y = 0; + glBegin(GL_TRIANGLE_FAN); + glVertex3f (0, 0, 1); for (i = 0; i < faces; i++) { - glVertex3f(0, 0, 1); - glVertex3f(x, y, 0); - + glVertex3f (x, y, 0); th += step; - x0 = cos (th + s2); - y0 = sin (th + s2); - x = cos (th); - y = sin (th); - - glVertex3f(x, y, 0); + x = cos (th); + y = sin (th); } + glVertex3f (1, 0, 0); glEnd(); return faces; } @@ -264,17 +254,18 @@ draw_cells (ModeInfo *mi) glClear (GL_DEPTH_BUFFER_BIT); - if (point_size <= 0) + if (vp->point_size <= 0) ; - else if (point_size < 3) + else if (vp->point_size < 3) { - glPointSize (point_size); + glPointSize (vp->point_size); for (nn = vp->nodes; nn; nn = nn->next) { glBegin (GL_POINTS); glColor4fv (nn->color2); glVertex2f (nn->x, nn->y); glEnd(); + mi->polygon_count++; } } else @@ -283,7 +274,7 @@ draw_cells (ModeInfo *mi) { int w = MI_WIDTH (mi); int h = MI_HEIGHT (mi); - int s = point_size; + int s = vp->point_size; int i; glColor4fv (nn->color2); @@ -291,7 +282,7 @@ draw_cells (ModeInfo *mi) glTranslatef (nn->x, nn->y, 0); glScalef (1.0 / w * s, 1.0 / h * s, 1); - glLineWidth (point_size / 10); + glLineWidth (vp->point_size / 10); nn->rot += (nn->rot < 0 ? -1 : 1); glRotatef (nn->rot, 0, 0, 1); @@ -304,10 +295,30 @@ draw_cells (ModeInfo *mi) glVertex2f ( 0.2, 0); glEnd (); glRotatef (360.0/5, 0, 0, 1); + mi->polygon_count++; } glPopMatrix(); } } + +#if 0 + glPushMatrix(); + glColor3f(1,1,1); + glBegin(GL_LINE_LOOP); + glVertex3f(0,0,0); + glVertex3f(1,0,0); + glVertex3f(1,1,0); + glVertex3f(0,1,0); + glEnd(); + glScalef(0.25, 0.25, 1); + glBegin(GL_LINE_LOOP); + glVertex3f(0,0,0); + glVertex3f(1,0,0); + glVertex3f(1,1,0); + glVertex3f(0,1,0); + glEnd(); + glPopMatrix(); +#endif } @@ -324,6 +335,27 @@ reshape_voronoi (ModeInfo *mi, int width, int height) glLoadIdentity(); glOrtho (0, 1, 1, 0, -1, 1); +# ifdef HAVE_MOBILE /* So much WTF */ + { + int rot = current_device_rotation(); + + glTranslatef (0.5, 0.5, 0); + // glScalef(0.19, 0.19, 0.19); + + if (rot == 180 || rot == -180) { + glTranslatef (1, 1, 0); + } else if (rot == 90 || rot == -270) { + glRotatef (180, 0, 0, 1); + glTranslatef (0, 1, 0); + } else if (rot == -90 || rot == 270) { + glRotatef (180, 0, 0, 1); + glTranslatef (1, 0, 0); + } + + glTranslatef(-0.5, -0.5, 0); + } +# endif + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -335,7 +367,7 @@ static node * find_node (ModeInfo *mi, GLfloat x, GLfloat y) { voronoi_configuration *vp = &vps[MI_SCREEN(mi)]; - int ps = (point_size < 5 ? 5 : point_size); + int ps = (vp->point_size < 5 ? 5 : vp->point_size); GLfloat hysteresis = (1.0 / MI_WIDTH (mi)) * ps; node *nn; for (nn = vp->nodes; nn; nn = nn->next) @@ -447,34 +479,22 @@ init_voronoi (ModeInfo *mi) { voronoi_configuration *vp; - if (!vps) { - vps = (voronoi_configuration *) - calloc (MI_NUM_SCREENS(mi), sizeof (voronoi_configuration)); - if (!vps) { - fprintf(stderr, "%s: out of memory\n", progname); - exit(1); - } - - vp = &vps[MI_SCREEN(mi)]; - } + MI_INIT (mi, vps); vp = &vps[MI_SCREEN(mi)]; vp->glx_context = init_GL(mi); - if (point_size < 0) point_size = 10; + vp->point_size = point_size; + if (vp->point_size < 0) vp->point_size = 10; + + if (MI_WIDTH(mi) > 2560) vp->point_size *= 2; /* Retina displays */ - vp->ncolors = 64; + vp->ncolors = 128; vp->colors = (XColor *) calloc (vp->ncolors, sizeof(XColor)); -#if 0 - make_random_colormap (0, 0, 0, - vp->colors, &vp->ncolors, - True, False, 0, False); -#else make_smooth_colormap (0, 0, 0, vp->colors, &vp->ncolors, False, False, False); -#endif reshape_voronoi (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); @@ -496,10 +516,10 @@ draw_voronoi (ModeInfo *mi) glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(vp->glx_context)); - glShadeModel(GL_SMOOTH); + glShadeModel(GL_FLAT); glEnable(GL_POINT_SMOOTH); - glEnable(GL_LINE_SMOOTH); - glEnable(GL_POLYGON_SMOOTH); +/* glEnable(GL_LINE_SMOOTH);*/ +/* glEnable(GL_POLYGON_SMOOTH);*/ glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);