X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fspheremonics.c;h=4ad36c8e170ad98bd5ed9e750e8dd780741bfcb3;hb=f8cf5ac7b2f53510f80a0eaf286a25298be17bfe;hp=30157710c53bb69ed186116abf1eb6aaf71b28ea;hpb=2d04c4f22466851aedb6ed0f2919d148f726b889;p=xscreensaver diff --git a/hacks/glx/spheremonics.c b/hacks/glx/spheremonics.c index 30157710..4ad36c8e 100644 --- a/hacks/glx/spheremonics.c +++ b/hacks/glx/spheremonics.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 2002, 2004 Jamie Zawinski +/* xscreensaver, Copyright (c) 2002-2012 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 @@ -60,39 +60,13 @@ * surfaces would be too hard. */ -#include - -extern XtAppContext app; - -#define PROGCLASS "Spheremonics" -#define HACK_INIT init_spheremonics -#define HACK_DRAW draw_spheremonics -#define HACK_RESHAPE reshape_spheremonics -#define HACK_HANDLE_EVENT spheremonics_handle_event -#define EVENT_MASK PointerMotionMask -#define ccs_opts xlockmore_opts - -#define DEF_DURATION "100" -#define DEF_SPIN "XYZ" -#define DEF_WANDER "False" -#define DEF_RESOLUTION "64" -#define DEF_BBOX "False" -#define DEF_GRID "True" -#define DEF_SMOOTH "True" -#define DEF_PARMS "(default)" - -#define DEFAULTS "*delay: 30000 \n" \ - "*resolution: " DEF_RESOLUTION "\n" \ - "*showFPS: False \n" \ - "*wireframe: False \n" \ - "*duration: " DEF_DURATION "\n" \ - "*spin: " DEF_SPIN "\n" \ - "*wander: " DEF_WANDER "\n" \ - "*bbox: " DEF_BBOX "\n" \ - "*grid: " DEF_GRID "\n" \ - "*smooth: " DEF_SMOOTH "\n" \ - "*parameters: " DEF_PARMS "\n" \ +#define DEFAULTS "*delay: 30000 \n" \ + "*showFPS: False \n" \ + "*wireframe: False \n" \ + "*labelfont: -*-helvetica-medium-r-normal-*-180-*\n" +# define refresh_spheremonics 0 +# define release_spheremonics 0 #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) @@ -106,7 +80,14 @@ extern XtAppContext app; #ifdef USE_GL /* whole file */ -#include +#define DEF_DURATION "100" +#define DEF_SPIN "XYZ" +#define DEF_WANDER "False" +#define DEF_RESOLUTION "64" +#define DEF_BBOX "False" +#define DEF_GRID "True" +#define DEF_SMOOTH "True" +#define DEF_PARMS "(default)" typedef struct { GLXContext *glx_context; @@ -130,9 +111,15 @@ typedef struct { int mesher; int polys1, polys2; /* polygon counts */ +# ifdef HAVE_GLBITMAP XFontStruct *font; GLuint font_list; +# else + texture_font_data *font_data; +# endif + int change_tick; + int done_once; } spheremonics_configuration; @@ -174,12 +161,12 @@ static argtype vars[] = { {&static_parms, "parameters", "Parameters", DEF_PARMS, t_String}, }; -ModeSpecOpt ccs_opts = {countof(opts), opts, countof(vars), vars, NULL}; +ENTRYPOINT ModeSpecOpt spheremonics_opts = {countof(opts), opts, countof(vars), vars, NULL}; /* Window management, etc */ -void +ENTRYPOINT void reshape_spheremonics (ModeInfo *mi, int width, int height) { GLfloat h = (GLfloat) height / (GLfloat) width; @@ -206,7 +193,7 @@ gl_init (ModeInfo *mi) /* spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)]; */ int wire = MI_IS_WIREFRAME(mi); - static GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0}; + static const GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0}; glEnable(GL_NORMALIZE); @@ -237,7 +224,15 @@ gl_init (ModeInfo *mi) lighting effect. */ glDisable(GL_CULL_FACE); - glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, TRUE); + glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, True); + } + + if (smooth_p) + { + glEnable (GL_LINE_SMOOTH); + glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable (GL_BLEND); } } @@ -320,28 +315,31 @@ draw_circle (ModeInfo *mi, Bool teeth_p) static void draw_bounding_box (ModeInfo *mi) { - spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)]; + /* spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)]; */ - static GLfloat c1[4] = { 0.2, 0.2, 0.6, 1.0 }; - static GLfloat c2[4] = { 1.0, 0.0, 0.0, 1.0 }; + static const GLfloat c1[4] = { 0.2, 0.2, 0.6, 1.0 }; + static const GLfloat c2[4] = { 1.0, 0.0, 0.0, 1.0 }; int wire = MI_IS_WIREFRAME(mi); - GLfloat x1 = cc->bbox[0].x; - GLfloat y1 = cc->bbox[0].y; - GLfloat z1 = cc->bbox[0].z; - GLfloat x2 = cc->bbox[1].x; - GLfloat y2 = cc->bbox[1].y; - GLfloat z2 = cc->bbox[1].z; + GLfloat x1,y1,z1,x2,y2,z2; -#if 1 +# if 0 + x1 = cc->bbox[0].x; + y1 = cc->bbox[0].y; + z1 = cc->bbox[0].z; + x2 = cc->bbox[1].x; + y2 = cc->bbox[1].y; + z2 = cc->bbox[1].z; +# else x1 = y1 = z1 = -0.5; x2 = y2 = z2 = 0.5; -#endif +# endif if (do_bbox && !wire) { glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, c1); glFrontFace(GL_CCW); + glEnable(GL_CULL_FACE); glBegin(wire ? GL_LINE_LOOP : GL_QUADS); glNormal3f(0, 1, 0); @@ -373,15 +371,13 @@ draw_bounding_box (ModeInfo *mi) glVertex3f(x2, y1, z1); glVertex3f(x2, y1, z2); glVertex3f(x2, y2, z2); glVertex3f(x2, y2, z1); glEnd(); + glDisable(GL_CULL_FACE); } - glPushAttrib (GL_LIGHTING); - glDisable (GL_LIGHTING); - - glColor3f (c2[0], c2[1], c2[2]); - if (do_grid) { + glDisable (GL_LIGHTING); + glColor3f (c2[0], c2[1], c2[2]); glPushMatrix(); glBegin(GL_LINES); glVertex3f(0, -0.66, 0); @@ -396,6 +392,7 @@ draw_bounding_box (ModeInfo *mi) } else { +#if 0 glBegin(GL_LINES); if (x1 > 0) x1 = 0; if (x2 < 0) x2 = 0; if (y1 > 0) y1 = 0; if (y2 < 0) y2 = 0; @@ -404,9 +401,8 @@ draw_bounding_box (ModeInfo *mi) glVertex3f(0 , y1, 0); glVertex3f(0, y2, 0); glVertex3f(0, 0, z1); glVertex3f(0, 0, z2); glEnd(); +#endif } - - glPopAttrib(); } @@ -436,9 +432,8 @@ do_tracer (ModeInfo *mi) if (s > 0.001) { - static GLfloat c[4] = { 0.6, 0.5, 1.0, 1.0 }; + static const GLfloat c[4] = { 0.6, 0.5, 1.0, 1.0 }; - glPushAttrib (GL_LIGHTING); glDisable (GL_LIGHTING); glPushMatrix(); @@ -450,7 +445,7 @@ do_tracer (ModeInfo *mi) draw_circle (mi, False); glPopMatrix(); - glPopAttrib(); + if (! MI_IS_WIREFRAME(mi)) glEnable (GL_LIGHTING); } cc->tracer += 5; @@ -668,14 +663,11 @@ generate_spheremonics (ModeInfo *mi) tweak_parameters (mi); - { - static Bool done = False; - if (!done || (0 == (random() % 20))) - { - init_colors (mi); - done = True; - } - } + if (!cc->done_once || (0 == (random() % 20))) + { + init_colors (mi); + cc->done_once = True; + } { glNewList(cc->dlist, GL_COMPILE); @@ -683,13 +675,10 @@ generate_spheremonics (ModeInfo *mi) glEndList(); glNewList(cc->dlist2, GL_COMPILE); - glPushAttrib (GL_LIGHTING); - glDisable (GL_LIGHTING); glPushMatrix(); glScalef (1.05, 1.05, 1.05); cc->polys2 = unit_spheremonics (mi, cc->resolution, 2, cc->m, cc->colors); glPopMatrix(); - glPopAttrib(); glEndList(); } } @@ -697,7 +686,7 @@ generate_spheremonics (ModeInfo *mi) -void +ENTRYPOINT void init_spheremonics (ModeInfo *mi) { spheremonics_configuration *cc; @@ -709,8 +698,6 @@ init_spheremonics (ModeInfo *mi) fprintf(stderr, "%s: out of memory\n", progname); exit(1); } - - cc = &ccs[MI_SCREEN(mi)]; } cc = &ccs[MI_SCREEN(mi)]; @@ -720,14 +707,6 @@ init_spheremonics (ModeInfo *mi) reshape_spheremonics (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } - if (smooth_p) - { - glEnable (GL_LINE_SMOOTH); - glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); - glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable (GL_BLEND); - } - { Bool spinx=False, spiny=False, spinz=False; double spin_speed = 1.0; @@ -739,6 +718,7 @@ init_spheremonics (ModeInfo *mi) if (*s == 'x' || *s == 'X') spinx = True; else if (*s == 'y' || *s == 'Y') spiny = True; else if (*s == 'z' || *s == 'Z') spinz = True; + else if (*s == '0') ; else { fprintf (stderr, @@ -763,7 +743,11 @@ init_spheremonics (ModeInfo *mi) cc->resolution = res; +# ifdef HAVE_GLBITMAP load_font (mi->dpy, "labelfont", &cc->font, &cc->font_list); +# else /* !HAVE_GLBITMAP */ + cc->font_data = load_texture_font (mi->dpy, "labelFont"); +# endif /* !HAVE_GLBITMAP */ cc->dlist = glGenLists(1); cc->dlist2 = glGenLists(1); @@ -783,7 +767,7 @@ init_spheremonics (ModeInfo *mi) } -Bool +ENTRYPOINT Bool spheremonics_handle_event (ModeInfo *mi, XEvent *event) { spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)]; @@ -805,7 +789,9 @@ spheremonics_handle_event (ModeInfo *mi, XEvent *event) } else if (event->xany.type == ButtonPress && (event->xbutton.button == Button4 || - event->xbutton.button == Button5)) + event->xbutton.button == Button5 || + event->xbutton.button == Button6 || + event->xbutton.button == Button7)) { gltrackball_mousewheel (cc->trackball, event->xbutton.button, 10, !!event->xbutton.state); @@ -836,7 +822,7 @@ spheremonics_handle_event (ModeInfo *mi, XEvent *event) } -void +ENTRYPOINT void draw_spheremonics (ModeInfo *mi) { spheremonics_configuration *cc = &ccs[MI_SCREEN(mi)]; @@ -846,6 +832,10 @@ draw_spheremonics (ModeInfo *mi) if (!cc->glx_context) return; + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(cc->glx_context)); + + gl_init(mi); + glShadeModel(GL_SMOOTH); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -877,8 +867,9 @@ draw_spheremonics (ModeInfo *mi) glCallList (cc->dlist); mi->polygon_count += cc->polys1; - if (cc->mesher >= 0 /* || mouse_p */) + if (cc->mesher >= 0 /* || cc->button_down_p */) { + glDisable (GL_LIGHTING); glCallList (cc->dlist2); mi->polygon_count += cc->polys2; if (cc->mesher >= 0) @@ -899,10 +890,15 @@ draw_spheremonics (ModeInfo *mi) cc->m[4], cc->m[5], cc->m[6], cc->m[7]); glColor3f(1.0, 1.0, 0.0); - print_gl_string (mi->dpy, cc->font, cc->font_list, + print_gl_string (mi->dpy, +# ifdef HAVE_GLBITMAP + cc->font, cc->font_list, +# else /* !HAVE_GLBITMAP */ + cc->font_data, +# endif /* !HAVE_GLBITMAP */ mi->xgwa.width, mi->xgwa.height, 10, mi->xgwa.height - 10, - buf); + buf, False); } if (!static_parms) @@ -923,4 +919,6 @@ draw_spheremonics (ModeInfo *mi) glXSwapBuffers(dpy, window); } +XSCREENSAVER_MODULE ("Spheremonics", spheremonics) + #endif /* USE_GL */