X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fskytentacles.c;h=9072f8f9abf0dc4807b7eedecec6987e0b13f71e;hb=39809ded547bdbb08207d3e514950425215b4410;hp=ace1e594073e558e65722d1f8b28e673e36beabb;hpb=f8cf5ac7b2f53510f80a0eaf286a25298be17bfe;p=xscreensaver diff --git a/hacks/glx/skytentacles.c b/hacks/glx/skytentacles.c index ace1e594..9072f8f9 100644 --- a/hacks/glx/skytentacles.c +++ b/hacks/glx/skytentacles.c @@ -1,4 +1,4 @@ -/* Sky Tentacles, Copyright (c) 2008 Jamie Zawinski +/* Sky Tentacles, Copyright (c) 2008-2014 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 @@ -14,7 +14,7 @@ "*showFPS: False \n" \ "*wireframe: False \n" \ -# define refresh_tentacles 0 +# define free_tentacles 0 # define release_tentacles 0 #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) @@ -39,6 +39,10 @@ static char *grey_texture[] = { #ifdef USE_GL /* whole file */ +# ifndef HAVE_JWZGLES +# define HAVE_POLYGONMODE +# endif + #define DEF_SPEED "1.0" #define DEF_SMOOTH "True" #define DEF_TEXTURE "True" @@ -167,8 +171,15 @@ reshape_tentacles (ModeInfo *mi, int width, int height) { tentacles_configuration *tc = &tcs[MI_SCREEN(mi)]; GLfloat h = (GLfloat) height / (GLfloat) width; + int y = 0; - glViewport (0, 0, (GLint) width, (GLint) height); + if (width > height * 5) { /* tiny window: show middle */ + height = width * 9/16; + y = -height/2; + h = height / (GLfloat) width; + } + + glViewport (0, y, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -352,9 +363,8 @@ draw_sucker (tentacle *t, Bool front_p) t->mi->polygon_count += points/2; } - static void -draw_tentacle (tentacle *t, Bool front_p) +draw_tentacle_1 (tentacle *t, Bool front_p, Bool outline_p) { tentacles_configuration *tc = &tcs[MI_SCREEN(t->mi)]; int i; @@ -409,8 +419,10 @@ draw_tentacle (tentacle *t, Bool front_p) } +# ifdef HAVE_POLYGONMODE if (cel_p) glPolygonMode (GL_FRONT_AND_BACK, (front_p ? GL_FILL : GL_LINE)); +# endif glPushMatrix(); glTranslatef (t->x, t->y, t->z); @@ -432,7 +444,7 @@ draw_tentacle (tentacle *t, Bool front_p) glPopAttrib(); } - if (!front_p) + if (!front_p || outline_p) glColor4fv (tc->outline_color); else if (wire) glColor4fv (t->tentacle_color); @@ -459,6 +471,9 @@ draw_tentacle (tentacle *t, Bool front_p) if (j <= indented_points/2 || j >= arg_slices-indented_points/2) r *= 0.75; /* indent the stripe */ + if (outline_p) + r *= 1.1; + ring[j].x = r * ucirc[j].x; ring[j].y = 0; ring[j].z = r * ucirc[j].y; @@ -502,7 +517,7 @@ draw_tentacle (tentacle *t, Bool front_p) GLfloat ts = j / (double) arg_slices; - if (!front_p) + if (!front_p || outline_p) glColor4fv (tc->outline_color); else if (j <= indented_points/2 || j >= arg_slices-indented_points/2) @@ -583,7 +598,13 @@ draw_tentacle (tentacle *t, Bool front_p) nsuckers = (i % segs_per_sucker) ? 0 : 1; } - if (front_p) + if (outline_p) + { + glColor4fv (tc->outline_color); + glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, + tc->outline_color); + } + else if (front_p) { glColor4fv (t->sucker_color); glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, @@ -619,10 +640,17 @@ draw_tentacle (tentacle *t, Bool front_p) scale = t->segments[i].thickness / arg_thickness; scale *= 0.7 * sucker_size; + glScalef (scale, scale, scale * 4); glTranslatef (0, 0, -0.1); /* embed */ + if (outline_p) + { + scale = 1.1; + glScalef (scale, scale, scale); + } + glTranslatef (1, 0, 0); /* left */ draw_sucker (t, front_p); @@ -639,7 +667,7 @@ draw_tentacle (tentacle *t, Bool front_p) /* Now draw the end caps. */ glLineWidth (tc->line_thickness); - if (i == 0 || i == t->nsegments-1) + if (!outline_p && (i == 0 || i == t->nsegments-1)) { int j; GLfloat ctrz = ctr.z + ((i == 0 ? -1 : 1) * @@ -709,6 +737,22 @@ draw_tentacle (tentacle *t, Bool front_p) } +static void +draw_tentacle (tentacle *t, Bool front_p) +{ +# ifndef HAVE_POLYGONMODE + Bool wire = MI_IS_WIREFRAME (t->mi); + if (!wire && cel_p && front_p) + { + draw_tentacle_1 (t, front_p, True); + glClear (GL_DEPTH_BUFFER_BIT); + } +# endif /* HAVE_POLYGONMODE */ + + draw_tentacle_1 (t, front_p, False); +} + + static void move_tentacle (tentacle *t) { @@ -770,39 +814,10 @@ tentacles_handle_event (ModeInfo *mi, XEvent *event) { tentacles_configuration *tc = &tcs[MI_SCREEN(mi)]; - if (event->xany.type == ButtonPress && - event->xbutton.button == Button1) - { - tc->button_down_p = True; - gltrackball_start (tc->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) - { - tc->button_down_p = False; - return True; - } - else if (event->xany.type == ButtonPress && - (event->xbutton.button == Button4 || - event->xbutton.button == Button5 || - event->xbutton.button == Button6 || - event->xbutton.button == Button7)) - { - gltrackball_mousewheel (tc->trackball, event->xbutton.button, 10, - !!event->xbutton.state); - return True; - } - else if (event->xany.type == MotionNotify && - tc->button_down_p) - { - gltrackball_track (tc->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } + if (gltrackball_event_handler (event, tc->trackball, + MI_WIDTH (mi), MI_HEIGHT (mi), + &tc->button_down_p)) + return True; else if (event->xany.type == KeyPress) { KeySym keysym; @@ -810,7 +825,7 @@ tentacles_handle_event (ModeInfo *mi, XEvent *event) XLookupString (&event->xkey, &c, 1, &keysym, 0); if (c == ' ') { - gltrackball_reset (tc->trackball); + gltrackball_reset (tc->trackball, 0, 0); return True; } } @@ -843,14 +858,7 @@ init_tentacles (ModeInfo *mi) int wire = MI_IS_WIREFRAME(mi); int i; - if (!tcs) { - tcs = (tentacles_configuration *) - calloc (MI_NUM_SCREENS(mi), sizeof (tentacles_configuration)); - if (!tcs) { - fprintf(stderr, "%s: out of memory\n", progname); - exit(1); - } - } + MI_INIT (mi, tcs); tc = &tcs[MI_SCREEN(mi)]; @@ -875,7 +883,7 @@ init_tentacles (ModeInfo *mi) glEnable (GL_LIGHT0); } - tc->trackball = gltrackball_init (); + tc->trackball = gltrackball_init (False); tc->left_p = !(random() % 5); @@ -993,7 +1001,7 @@ draw_tentacles (ModeInfo *mi) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix (); - + glRotatef(current_device_rotation(), 0, 0, 1); # if 1 glScalef (3, 3, 3); @@ -1017,7 +1025,6 @@ draw_tentacles (ModeInfo *mi) # endif gltrackball_rotate (tc->trackball); - glRotatef(current_device_rotation(), 0, 0, 1); mi->polygon_count = 0;