X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fpolytopes.c;h=4f401d50a3b9b9b14f45f3fe0976b67a00a0d343;hb=aa75c7476aeaa84cf3abc192b376a8b03c325213;hp=257481554614f7588c5ae8687e3655f397d9d2dc;hpb=c494fd2e6b3b25582375d62e40f4f5cc984ca424;p=xscreensaver diff --git a/hacks/glx/polytopes.c b/hacks/glx/polytopes.c index 25748155..4f401d50 100644 --- a/hacks/glx/polytopes.c +++ b/hacks/glx/polytopes.c @@ -4,7 +4,7 @@ static const char sccsid[] = "@(#)polytopes.c 1.2 05/09/28 xlockmore"; #endif -/* Copyright (c) 2003-2007 Carsten Steger . */ +/* Copyright (c) 2003-2009 Carsten Steger . */ /* * Permission to use, copy, modify, and distribute this software and its @@ -23,6 +23,7 @@ static const char sccsid[] = "@(#)polytopes.c 1.2 05/09/28 xlockmore"; * C. Steger - 03/08/10: Initial version * C. Steger - 05/09/28: Added trackball support * C. Steger - 07/01/23: Improved 4d trackball support + * C. Steger - 09/08/23: Removed check-config.pl warnings */ /* @@ -52,71 +53,45 @@ static const char sccsid[] = "@(#)polytopes.c 1.2 05/09/28 xlockmore"; #define GOLDENINV22 0.27009075673772645360 /* (((sqrt(5)-1)/2)^2)/sqrt(2) */ #define DISP_WIREFRAME 0 -#define DISP_WIREFRAME_STR "0" #define DISP_SURFACE 1 -#define DISP_SURFACE_STR "1" #define DISP_TRANSPARENT 2 -#define DISP_TRANSPARENT_STR "2" #define POLYTOPE_RANDOM -1 -#define POLYTOPE_RANDOM_STR "-1" #define POLYTOPE_5_CELL 0 -#define POLYTOPE_5_CELL_STR "0" #define POLYTOPE_8_CELL 1 -#define POLYTOPE_8_CELL_STR "1" #define POLYTOPE_16_CELL 2 -#define POLYTOPE_16_CELL_STR "2" #define POLYTOPE_24_CELL 3 -#define POLYTOPE_24_CELL_STR "3" #define POLYTOPE_120_CELL 4 -#define POLYTOPE_120_CELL_STR "4" #define POLYTOPE_600_CELL 5 -#define POLYTOPE_600_CELL_STR "5" #define POLYTOPE_LAST_CELL POLYTOPE_600_CELL #define COLORS_SINGLE 0 -#define COLORS_SINGLE_STR "0" #define COLORS_DEPTH 1 -#define COLORS_DEPTH_STR "1" #define DISP_3D_PERSPECTIVE 0 -#define DISP_3D_PERSPECTIVE_STR "0" #define DISP_3D_ORTHOGRAPHIC 1 -#define DISP_3D_ORTHOGRAPHIC_STR "1" #define DISP_4D_PERSPECTIVE 0 #define DISP_4D_PERSPECTIVE_STR "0" #define DISP_4D_ORTHOGRAPHIC 1 #define DISP_4D_ORTHOGRAPHIC_STR "1" -#define DALPHA 1.1 -#define DALPHA_STR "1.1" -#define DBETA 1.3 -#define DBETA_STR "1.3" -#define DDELTA 1.5 -#define DDELTA_STR "1.5" -#define DZETA 1.7 -#define DZETA_STR "1.7" -#define DETA 1.9 -#define DETA_STR "1.9" -#define DTHETA 2.1 -#define DTHETA_STR "2.1" - -#define DEF_DISPLAY_MODE DISP_TRANSPARENT_STR -#define DEF_POLYTOPE POLYTOPE_RANDOM_STR -#define DEF_COLORS COLORS_DEPTH_STR -#define DEF_3D_PROJECTION DISP_3D_PERSPECTIVE_STR -#define DEF_4D_PROJECTION DISP_4D_PERSPECTIVE_STR -#define DEF_DALPHA DALPHA_STR -#define DEF_DBETA DBETA_STR -#define DEF_DDELTA DDELTA_STR -#define DEF_DZETA DZETA_STR -#define DEF_DETA DETA_STR -#define DEF_DTHETA DTHETA_STR +#define DEF_DISPLAY_MODE "transparent" +#define DEF_POLYTOPE "random" +#define DEF_COLORS "depth" +#define DEF_PROJECTION_3D "perspective" +#define DEF_PROJECTION_4D "perspective" +#define DEF_SPEEDWX "1.1" +#define DEF_SPEEDWY "1.3" +#define DEF_SPEEDWZ "1.5" +#define DEF_SPEEDXY "1.7" +#define DEF_SPEEDXZ "1.9" +#define DEF_SPEEDYZ "2.1" #ifdef STANDALONE # define DEFAULTS "*delay: 25000 \n" \ - "*showFPS: False \n" + "*showFPS: False \n" \ + "*suppressRotationAnimation: True\n" \ # define refresh_polytopes 0 # include "xlockmore.h" /* from the xscreensaver distribution */ @@ -126,7 +101,9 @@ static const char sccsid[] = "@(#)polytopes.c 1.2 05/09/28 xlockmore"; #ifdef USE_GL -#include +#ifndef HAVE_JWXYZ +# include +#endif #include "gltrackball.h" @@ -140,10 +117,15 @@ ModStruct polytopes_description = #endif +static char *mode; static int display_mode; +static char *poly_str; static int polytope; +static char *color_str; static int color_mode; +static char *proj_3d; static int projection_3d; +static char *proj_4d; static int projection_4d; static float speed_wx; static float speed_wy; @@ -158,62 +140,45 @@ static const float offset3d[4] = { 0.0, 0.0, -2.0, 0.0 }; static XrmOptionDescRec opts[] = { - {"-mode", ".polytopes.displayMode", XrmoptionSepArg, 0 }, - {"-wireframe", ".polytopes.displayMode", XrmoptionNoArg, - DISP_WIREFRAME_STR }, - {"-surface", ".polytopes.displayMode", XrmoptionNoArg, - DISP_SURFACE_STR }, - {"-transparent", ".polytopes.displayMode", XrmoptionNoArg, - DISP_TRANSPARENT_STR }, - {"-random", ".polytopes.polytope", XrmoptionNoArg, - POLYTOPE_RANDOM_STR }, - - {"-polytope", ".polytopes.polytope", XrmoptionSepArg, 0 }, - {"-5-cell", ".polytopes.polytope", XrmoptionNoArg, - POLYTOPE_5_CELL_STR }, - {"-8-cell", ".polytopes.polytope", XrmoptionNoArg, - POLYTOPE_8_CELL_STR }, - {"-16-cell", ".polytopes.polytope", XrmoptionNoArg, - POLYTOPE_16_CELL_STR }, - {"-24-cell", ".polytopes.polytope", XrmoptionNoArg, - POLYTOPE_24_CELL_STR }, - {"-120-cell", ".polytopes.polytope", XrmoptionNoArg, - POLYTOPE_120_CELL_STR }, - {"-600-cell", ".polytopes.polytope", XrmoptionNoArg, - POLYTOPE_600_CELL_STR }, - {"-single-color", ".polytopes.colors", XrmoptionNoArg, - COLORS_SINGLE_STR }, - {"-depth-colors", ".polytopes.colors", XrmoptionNoArg, - COLORS_DEPTH_STR }, - {"-perspective-3d", ".polytopes.projection3d", XrmoptionNoArg, - DISP_3D_PERSPECTIVE_STR }, - {"-orthographic-3d", ".polytopes.projection3d", XrmoptionNoArg, - DISP_3D_ORTHOGRAPHIC_STR }, - {"-perspective-4d", ".polytopes.projection4d", XrmoptionNoArg, - DISP_4D_PERSPECTIVE_STR }, - {"-orthographic-4d", ".polytopes.projection4d", XrmoptionNoArg, - DISP_4D_ORTHOGRAPHIC_STR }, - {"-speed-wx", ".polytopes.speedwx", XrmoptionSepArg, 0 }, - {"-speed-wy", ".polytopes.speedwy", XrmoptionSepArg, 0 }, - {"-speed-wz", ".polytopes.speedwz", XrmoptionSepArg, 0 }, - {"-speed-xy", ".polytopes.speedxy", XrmoptionSepArg, 0 }, - {"-speed-xz", ".polytopes.speedxz", XrmoptionSepArg, 0 }, - {"-speed-yz", ".polytopes.speedyz", XrmoptionSepArg, 0 } + {"-mode", ".displayMode", XrmoptionSepArg, 0 }, + {"-wireframe", ".displayMode", XrmoptionNoArg, "wireframe" }, + {"-surface", ".displayMode", XrmoptionNoArg, "surface" }, + {"-transparent", ".displayMode", XrmoptionNoArg, "transparent" }, + {"-polytope", ".polytope", XrmoptionSepArg, 0 }, + {"-random", ".polytope", XrmoptionNoArg, "random" }, + {"-5-cell", ".polytope", XrmoptionNoArg, "5-cell" }, + {"-8-cell", ".polytope", XrmoptionNoArg, "8-cell" }, + {"-16-cell", ".polytope", XrmoptionNoArg, "16-cell" }, + {"-24-cell", ".polytope", XrmoptionNoArg, "24-cell" }, + {"-120-cell", ".polytope", XrmoptionNoArg, "120-cell" }, + {"-600-cell", ".polytope", XrmoptionNoArg, "600-cell" }, + {"-single-color", ".colors", XrmoptionNoArg, "single" }, + {"-depth-colors", ".colors", XrmoptionNoArg, "depth" }, + {"-perspective-3d", ".projection3d", XrmoptionNoArg, "perspective" }, + {"-orthographic-3d", ".projection3d", XrmoptionNoArg, "orthographic" }, + {"-perspective-4d", ".projection4d", XrmoptionNoArg, "perspective" }, + {"-orthographic-4d", ".projection4d", XrmoptionNoArg, "orthographic" }, + {"-speed-wx", ".speedwx", XrmoptionSepArg, 0 }, + {"-speed-wy", ".speedwy", XrmoptionSepArg, 0 }, + {"-speed-wz", ".speedwz", XrmoptionSepArg, 0 }, + {"-speed-xy", ".speedxy", XrmoptionSepArg, 0 }, + {"-speed-xz", ".speedxz", XrmoptionSepArg, 0 }, + {"-speed-yz", ".speedyz", XrmoptionSepArg, 0 } }; static argtype vars[] = { - { &display_mode, "displayMode", "DisplayMode", DEF_DISPLAY_MODE, t_Int }, - { &polytope, "polytope", "Polytope", DEF_POLYTOPE, t_Int }, - { &color_mode, "colors", "Colors", DEF_COLORS, t_Int }, - { &projection_3d, "projection3d", "Projection3d",DEF_3D_PROJECTION, t_Int }, - { &projection_4d, "projection4d", "Projection4d",DEF_4D_PROJECTION, t_Int }, - { &speed_wx, "speedwx", "Speedwx", DEF_DALPHA, t_Float}, - { &speed_wy, "speedwy", "Speedwy", DEF_DBETA, t_Float}, - { &speed_wz, "speedwz", "Speedwz", DEF_DDELTA, t_Float}, - { &speed_xy, "speedxy", "Speedxy", DEF_DZETA, t_Float}, - { &speed_xz, "speedxz", "Speedxz", DEF_DETA, t_Float}, - { &speed_yz, "speedyz", "Speedyz", DEF_DTHETA, t_Float} + { &mode, "displayMode", "DisplayMode", DEF_DISPLAY_MODE, t_String }, + { &poly_str, "polytope", "Polytope", DEF_POLYTOPE, t_String }, + { &color_str, "colors", "Colors", DEF_COLORS, t_String }, + { &proj_3d, "projection3d", "Projection3d",DEF_PROJECTION_3D, t_String }, + { &proj_4d, "projection4d", "Projection4d",DEF_PROJECTION_4D, t_String }, + { &speed_wx, "speedwx", "Speedwx", DEF_SPEEDWX, t_Float}, + { &speed_wy, "speedwy", "Speedwy", DEF_SPEEDWY, t_Float}, + { &speed_wz, "speedwz", "Speedwz", DEF_SPEEDWZ, t_Float}, + { &speed_xy, "speedxy", "Speedxy", DEF_SPEEDXY, t_Float}, + { &speed_xz, "speedxz", "Speedxz", DEF_SPEEDXZ, t_Float}, + { &speed_yz, "speedyz", "Speedyz", DEF_SPEEDYZ, t_Float} }; static OptionStruct desc[] = @@ -2807,11 +2772,6 @@ static void set_colors(ModeInfo *mi) static void init(ModeInfo *mi) { - static const GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; - static const GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; - static const GLfloat light_specular[] = { 0.0, 0.0, 0.0, 1.0 }; - static const GLfloat light_position[] = { 0.0, 0.0, 1.0, 0.0 }; - static const GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; polytopesstruct *pp = &poly[MI_SCREEN(mi)]; set_colors(mi); @@ -2825,62 +2785,6 @@ static void init(ModeInfo *mi) pp->tick = 0; pp->poly = 0; - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - if (projection_3d == DISP_3D_PERSPECTIVE) - gluPerspective(60.0,1.0,0.1,100.0); - else - glOrtho(-1.0,1.0,-1.0,1.0,0.1,100.0);; - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - if (display_mode == DISP_WIREFRAME) - { - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - glDisable(GL_LIGHT0); - glDisable(GL_BLEND); - } - else if (display_mode == DISP_SURFACE) - { - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); - glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); - glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); - glLightfv(GL_LIGHT0,GL_POSITION,light_position); - glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); - glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,0.0); - glDepthMask(GL_TRUE); - glDisable(GL_BLEND); - } - else if (display_mode == DISP_TRANSPARENT) - { - glDisable(GL_DEPTH_TEST); - glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); - glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); - glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); - glLightfv(GL_LIGHT0,GL_POSITION,light_position); - glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); - glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,0.0); - glDepthMask(GL_FALSE); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA,GL_ONE); - } - else - { - glDisable(GL_DEPTH_TEST); - glDisable(GL_LIGHTING); - glDisable(GL_LIGHT0); - glDisable(GL_BLEND); - } } @@ -2924,6 +2828,7 @@ static void display_polytopes(ModeInfo *mi) { gluPerspective(60.0,pp->aspect,0.1,100.0); } + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -2967,9 +2872,12 @@ ENTRYPOINT void reshape_polytopes(ModeInfo *mi, int width, int height) ENTRYPOINT Bool polytopes_handle_event(ModeInfo *mi, XEvent *event) { - Display *display = MI_DISPLAY(mi); polytopesstruct *pp = &poly[MI_SCREEN(mi)]; - KeySym sym; + KeySym sym = 0; + char c = 0; + + if (event->xany.type == KeyPress || event->xany.type == KeyRelease) + XLookupString (&event->xkey, &c, 1, &sym, 0); if (event->xany.type == ButtonPress && event->xbutton.button == Button1) @@ -2988,7 +2896,6 @@ ENTRYPOINT Bool polytopes_handle_event(ModeInfo *mi, XEvent *event) } else if (event->xany.type == KeyPress) { - sym = XKeycodeToKeysym(display,event->xkey.keycode,0); if (sym == XK_Shift_L || sym == XK_Shift_R) { pp->current_trackball = 1; @@ -3001,7 +2908,6 @@ ENTRYPOINT Bool polytopes_handle_event(ModeInfo *mi, XEvent *event) } else if (event->xany.type == KeyRelease) { - sym = XKeycodeToKeysym(display,event->xkey.keycode,0); if (sym == XK_Shift_L || sym == XK_Shift_R) { pp->current_trackball = 0; @@ -3051,11 +2957,105 @@ ENTRYPOINT void init_polytopes(ModeInfo *mi) } pp = &poly[MI_SCREEN(mi)]; - pp->trackballs[0] = gltrackball_init(); - pp->trackballs[1] = gltrackball_init(); + pp->trackballs[0] = gltrackball_init(True); + pp->trackballs[1] = gltrackball_init(True); pp->current_trackball = 0; pp->button_pressed = False; + /* Set the display mode. */ + if (!strcasecmp(mode,"wireframe") || !strcasecmp(mode,"0")) + { + display_mode = DISP_WIREFRAME; + } + else if (!strcasecmp(mode,"surface") || !strcasecmp(mode,"1")) + { + display_mode = DISP_SURFACE; + } + else if (!strcasecmp(mode,"transparent") || !strcasecmp(mode,"2")) + { + display_mode = DISP_TRANSPARENT; + } + else + { + display_mode = DISP_TRANSPARENT; + } + + /* Set the Klein bottle. */ + if (!strcasecmp(poly_str,"random") || !strcasecmp(poly_str,"-1")) + { + polytope = POLYTOPE_RANDOM; + } + else if (!strcasecmp(poly_str,"5-cell") || !strcasecmp(poly_str,"0")) + { + polytope = POLYTOPE_5_CELL; + } + else if (!strcasecmp(poly_str,"8-cell") || !strcasecmp(poly_str,"1")) + { + polytope = POLYTOPE_8_CELL; + } + else if (!strcasecmp(poly_str,"16-cell") || !strcasecmp(poly_str,"2")) + { + polytope = POLYTOPE_16_CELL; + } + else if (!strcasecmp(poly_str,"24-cell") || !strcasecmp(poly_str,"3")) + { + polytope = POLYTOPE_24_CELL; + } + else if (!strcasecmp(poly_str,"120-cell") || !strcasecmp(poly_str,"4")) + { + polytope = POLYTOPE_120_CELL; + } + else if (!strcasecmp(poly_str,"600-cell") || !strcasecmp(poly_str,"5")) + { + polytope = POLYTOPE_600_CELL; + } + else + { + polytope = POLYTOPE_RANDOM; + } + + /* Set the color mode. */ + if (!strcasecmp(color_str,"single") || !strcasecmp(color_str,"0")) + { + color_mode = COLORS_SINGLE; + } + else if (!strcasecmp(color_str,"depth") || !strcasecmp(color_str,"1")) + { + color_mode = COLORS_DEPTH; + } + else + { + color_mode = COLORS_DEPTH; + } + + /* Set the 3d projection mode. */ + if (!strcasecmp(proj_3d,"perspective") || !strcasecmp(proj_3d,"0")) + { + projection_3d = DISP_3D_PERSPECTIVE; + } + else if (!strcasecmp(proj_3d,"orthographic") || !strcasecmp(proj_3d,"1")) + { + projection_3d = DISP_3D_ORTHOGRAPHIC; + } + else + { + projection_3d = DISP_3D_PERSPECTIVE; + } + + /* Set the 4d projection mode. */ + if (!strcasecmp(proj_4d,"perspective") || !strcasecmp(proj_4d,"0")) + { + projection_4d = DISP_4D_PERSPECTIVE; + } + else if (!strcasecmp(proj_4d,"orthographic") || !strcasecmp(proj_4d,"1")) + { + projection_4d = DISP_4D_ORTHOGRAPHIC; + } + else + { + projection_4d = DISP_4D_PERSPECTIVE; + } + /* make multiple screens rotate at slightly different rates. */ pp->speed_scale = 0.9 + frand(0.3); @@ -3078,6 +3078,12 @@ ENTRYPOINT void init_polytopes(ModeInfo *mi) */ ENTRYPOINT void draw_polytopes(ModeInfo *mi) { + static const GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; + static const GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; + static const GLfloat light_specular[] = { 0.0, 0.0, 0.0, 1.0 }; + static const GLfloat light_position[] = { 0.0, 0.0, 1.0, 0.0 }; + static const GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; + Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); polytopesstruct *hp; @@ -3092,6 +3098,64 @@ ENTRYPOINT void draw_polytopes(ModeInfo *mi) glXMakeCurrent(display,window,*(hp->glx_context)); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if (projection_3d == DISP_3D_PERSPECTIVE) + gluPerspective(60.0,1.0,0.1,100.0); + else + glOrtho(-1.0,1.0,-1.0,1.0,0.1,100.0);; + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + if (display_mode == DISP_WIREFRAME) + { + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + glDisable(GL_BLEND); + } + else if (display_mode == DISP_SURFACE) + { + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); + glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); + glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); + glLightfv(GL_LIGHT0,GL_POSITION,light_position); + glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); + glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,0.0); + glDepthMask(GL_TRUE); + glDisable(GL_BLEND); + } + else if (display_mode == DISP_TRANSPARENT) + { + glDisable(GL_DEPTH_TEST); + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient); + glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse); + glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular); + glLightfv(GL_LIGHT0,GL_POSITION,light_position); + glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,mat_specular); + glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,0.0); + glDepthMask(GL_FALSE); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA,GL_ONE); + } + else + { + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glDisable(GL_LIGHT0); + glDisable(GL_BLEND); + } + + glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity();