X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Ftronbit.c;h=b0ee542e0a672373f60252217cc4b954dfed3c9d;hb=6afd6db0ae9396cd7ff897ade597cd5483f49b0e;hp=98cbf287127a4b8425a7619f93fc3ec9605cad6e;hpb=ec8d2b32b63649e6d32bdfb306eda062769af823;p=xscreensaver diff --git a/hacks/glx/tronbit.c b/hacks/glx/tronbit.c index 98cbf287..b0ee542e 100644 --- a/hacks/glx/tronbit.c +++ b/hacks/glx/tronbit.c @@ -1,4 +1,4 @@ -/* tronbit, Copyright (c) 2011 Jamie Zawinski +/* tronbit, Copyright (c) 2011-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 @@ -236,6 +236,20 @@ animate_bits (ModeInfo *mi, bit_state omodel, bit_state nmodel, GLfloat ratio) int polys = 0; GLfloat scale = sin (ratio * M_PI / 2); GLfloat osize, nsize, small; + int wire = MI_IS_WIREFRAME(mi); + + glShadeModel(GL_SMOOTH); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_NORMALIZE); + glEnable(GL_CULL_FACE); + + if (!wire) + { + glEnable(GL_LIGHTING); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + } if ((omodel == BIT_IDLE1 || omodel == BIT_IDLE2) && (nmodel == BIT_IDLE1 || nmodel == BIT_IDLE2)) @@ -273,11 +287,6 @@ draw_histogram (ModeInfo *mi, GLfloat ratio) int overlays = 5; int k; - glPushAttrib (GL_TRANSFORM_BIT | /* for matrix contents */ - GL_ENABLE_BIT | /* for various glDisable calls */ - GL_CURRENT_BIT | /* for glColor3f() */ - GL_LIST_BIT); /* for glListBase() */ - glDisable (GL_TEXTURE_2D); glDisable (GL_LIGHTING); glDisable (GL_BLEND); @@ -292,7 +301,8 @@ draw_histogram (ModeInfo *mi, GLfloat ratio) glPushMatrix(); glLoadIdentity(); - gluOrtho2D (0, mi->xgwa.width, 0, mi->xgwa.height); + glRotatef(current_device_rotation(), 0, 0, 1); + glOrtho (0, mi->xgwa.width, 0, mi->xgwa.height, -1, 1); for (k = 0; k < overlays; k++) { @@ -307,6 +317,7 @@ draw_histogram (ModeInfo *mi, GLfloat ratio) for (i = 0; i < samples; i++) { GLfloat x = i; + if (j >= samples) j = 0; GLfloat y = bp->histogram[j]; GLfloat z = 0; @@ -317,7 +328,7 @@ draw_histogram (ModeInfo *mi, GLfloat ratio) y *= scaley; glVertex3f (x, y, z); - if (++j >= samples) j = 0; + ++j; polys++; } glEnd(); @@ -328,8 +339,6 @@ draw_histogram (ModeInfo *mi, GLfloat ratio) glMatrixMode(GL_PROJECTION); glPopMatrix(); - glPopAttrib(); - glMatrixMode(GL_MODELVIEW); return polys; @@ -365,45 +374,22 @@ bit_handle_event (ModeInfo *mi, XEvent *event) { bit_configuration *bp = &bps[MI_SCREEN(mi)]; - if (event->xany.type == ButtonPress && - event->xbutton.button == Button1) - { - bp->button_down_p = True; - gltrackball_start (bp->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) - { - bp->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 (bp->trackball, event->xbutton.button, 3, - !!event->xbutton.state); - return True; - } - else if (event->xany.type == MotionNotify && - bp->button_down_p) - { - gltrackball_track (bp->trackball, - event->xmotion.x, event->xmotion.y, - MI_WIDTH (mi), MI_HEIGHT (mi)); - return True; - } + if (gltrackball_event_handler (event, bp->trackball, + MI_WIDTH (mi), MI_HEIGHT (mi), + &bp->button_down_p)) + return True; else if (event->xany.type == KeyPress) { KeySym keysym; char c = 0; XLookupString (&event->xkey, &c, 1, &keysym, 0); - if (c == ' ' || c == '1' || c == '0') + + if (keysym == XK_Up || keysym == XK_Left || keysym == XK_Prior) + c = '1'; + else if (keysym == XK_Down || keysym == XK_Right || keysym == XK_Next) + c = '0'; + + if (c == ' ' || c == '\t' || c == '\n' || c == '1' || c == '0') { bp->kbd = c; return True; @@ -418,7 +404,6 @@ ENTRYPOINT void init_bit (ModeInfo *mi) { bit_configuration *bp; - int wire = MI_IS_WIREFRAME(mi); int i; if (!bps) { @@ -436,24 +421,6 @@ init_bit (ModeInfo *mi) reshape_bit (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); - if (!wire) - { - GLfloat pos[4] = {1.0, 1.0, 1.0, 0.0}; - GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0}; - GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; - GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0}; - - glEnable(GL_LIGHTING); - glEnable(GL_LIGHT0); - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - - glLightfv(GL_LIGHT0, GL_POSITION, pos); - glLightfv(GL_LIGHT0, GL_AMBIENT, amb); - glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); - glLightfv(GL_LIGHT0, GL_SPECULAR, spc); - } - { double spin_speed = 3.0; double wander_speed = 0.03 * speed; @@ -465,7 +432,7 @@ init_bit (ModeInfo *mi) spin_accel, do_wander ? wander_speed : 0, False); - bp->trackball = gltrackball_init (); + bp->trackball = gltrackball_init (False); } for (i = 0; i < countof(bp->dlists); i++) @@ -490,22 +457,32 @@ draw_bit (ModeInfo *mi) bit_configuration *bp = &bps[MI_SCREEN(mi)]; Display *dpy = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); + int wire = MI_IS_WIREFRAME(mi); if (!bp->glx_context) return; glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context)); - glShadeModel(GL_SMOOTH); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glEnable(GL_DEPTH_TEST); - glEnable(GL_NORMALIZE); - glEnable(GL_CULL_FACE); + if (!wire) + { + GLfloat pos[4] = {1.0, 1.0, 1.0, 0.0}; + GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0}; + GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; + GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0}; - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0, GL_POSITION, pos); + glLightfv(GL_LIGHT0, GL_AMBIENT, amb); + glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); + glLightfv(GL_LIGHT0, GL_SPECULAR, spc); + } glPushMatrix (); - + glRotatef(current_device_rotation(), 0, 0, 1); glScalef(1.1, 1.1, 1.1); { @@ -514,7 +491,6 @@ draw_bit (ModeInfo *mi) glTranslatef((x - 0.5) * 11, (y - 0.5) * 5, (z - 0.5) * 3); - gltrackball_rotate (bp->trackball); get_rotation (bp->rot, &x, &y, &z, !bp->button_down_p); @@ -527,7 +503,6 @@ draw_bit (ModeInfo *mi) glScalef (6, 6, 6); - { int nmodel = bp->history [bp->history_fp]; int omodel = bp->history [bp->history_fp > 0