X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fglx%2Fflyingtoasters.c;h=52e59586db08d610b44b1ea06ea4b022111250f4;hp=32062f1b7d12e993d56ef45fe7a4b20b636f150d;hb=6b1c86cf395f59389e4ece4ea8f4bea2c332745b;hpb=9c9d475ff889ed8be02e8ce8c17da28b93278fca diff --git a/hacks/glx/flyingtoasters.c b/hacks/glx/flyingtoasters.c index 32062f1b..52e59586 100644 --- a/hacks/glx/flyingtoasters.c +++ b/hacks/glx/flyingtoasters.c @@ -1,4 +1,4 @@ -/* flyingtoasters, Copyright (c) 2003, 2004 Jamie Zawinski +/* flyingtoasters, Copyright (c) 2003-2006 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 @@ -26,36 +26,22 @@ * bitmapped toasters won't get all huffy at us. */ -#include - -extern XtAppContext app; - -#define PROGCLASS "FlyingToasters" -#define HACK_INIT init_toasters -#define HACK_DRAW draw_toasters -#define HACK_RESHAPE reshape_toasters -#define HACK_HANDLE_EVENT toaster_handle_event -#define EVENT_MASK PointerMotionMask -#define sws_opts xlockmore_opts - -#define DEF_SPEED "1.0" -#define DEF_NTOASTERS "20" -#define DEF_NSLICES "25" -#define DEF_TEXTURE "True" - #define DEFAULTS "*delay: 30000 \n" \ "*showFPS: False \n" \ "*wireframe: False \n" \ - "*speed: " DEF_SPEED " \n" \ - "*ntoasters: " DEF_NTOASTERS "\n" \ - "*nslices: " DEF_NSLICES "\n" \ - "*texture: " DEF_TEXTURE "\n" \ /* #define DEBUG */ +# define refresh_toasters 0 +# define release_toasters 0 #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) +#define DEF_SPEED "1.0" +#define DEF_NTOASTERS "20" +#define DEF_NSLICES "25" +#define DEF_TEXTURE "True" + #undef BELLRAND #define BELLRAND(n) ((frand((n)) + frand((n)) + frand((n))) / 3) @@ -69,16 +55,13 @@ extern XtAppContext app; #ifdef USE_GL /* whole file */ -#include - - #include "gllist.h" -extern struct gllist +extern const struct gllist *toaster, *toaster_base, *toaster_handle, *toaster_handle2, *toaster_jet, *toaster_knob, *toaster_slots, *toaster_wing, *toast, *toast2; -struct gllist **all_objs[] = { +static const struct gllist * const *all_objs[] = { &toaster, &toaster_base, &toaster_handle, &toaster_handle2, &toaster_jet, &toaster_knob, &toaster_slots, &toaster_wing, &toast, &toast2 }; @@ -98,7 +81,7 @@ struct gllist **all_objs[] = { #define GRID_DEPTH 500 -static struct { GLfloat x, y; } nice_views[] = { +static const struct { GLfloat x, y; } nice_views[] = { { 0, 120 }, { 0, -120 }, { 12, 28 }, /* this is a list of viewer rotations that look nice. */ @@ -132,6 +115,7 @@ typedef struct { GLfloat view_x, view_y; int view_steps, view_tick; Bool auto_tracking_p; + int track_tick; GLuint *dlists; GLuint chrome_texture; @@ -153,8 +137,8 @@ static XrmOptionDescRec opts[] = { { "-speed", ".speed", XrmoptionSepArg, 0 }, { "-ntoasters", ".ntoasters", XrmoptionSepArg, 0 }, { "-nslices", ".nslices", XrmoptionSepArg, 0 }, - {"-texture", ".texture", XrmoptionNoArg, (caddr_t) "True" }, - {"+texture", ".texture", XrmoptionNoArg, (caddr_t) "False" }, + {"-texture", ".texture", XrmoptionNoArg, "True" }, + {"+texture", ".texture", XrmoptionNoArg, "False" }, }; static argtype vars[] = { @@ -164,7 +148,7 @@ static argtype vars[] = { {&do_texture, "texture", "Texture", DEF_TEXTURE, t_Bool}, }; -ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL}; +ENTRYPOINT ModeSpecOpt toasters_opts = {countof(opts), opts, countof(vars), vars, NULL}; static void @@ -259,9 +243,8 @@ auto_track (ModeInfo *mi) /* if we're not moving, maybe start moving. Otherwise, do nothing. */ if (! bp->auto_tracking_p) { - static int tick = 0; - if (++tick < 200/speed) return; - tick = 0; + if (++bp->track_tick < 200/speed) return; + bp->track_tick = 0; if (! (random() % 5)) bp->auto_tracking_p = True; else @@ -297,7 +280,7 @@ auto_track (ModeInfo *mi) /* Window management, etc */ -void +ENTRYPOINT void reshape_toasters (ModeInfo *mi, int width, int height) { GLfloat h = (GLfloat) height / (GLfloat) width; @@ -318,13 +301,13 @@ reshape_toasters (ModeInfo *mi, int width, int height) } -Bool -toaster_handle_event (ModeInfo *mi, XEvent *event) +ENTRYPOINT Bool +toasters_handle_event (ModeInfo *mi, XEvent *event) { toaster_configuration *bp = &bps[MI_SCREEN(mi)]; if (event->xany.type == ButtonPress && - event->xbutton.button & Button1) + event->xbutton.button == Button1) { bp->button_down_p = True; gltrackball_start (bp->user_trackball, @@ -333,11 +316,21 @@ toaster_handle_event (ModeInfo *mi, XEvent *event) return True; } else if (event->xany.type == ButtonRelease && - event->xbutton.button & Button1) + 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->user_trackball, event->xbutton.button, 5, + !event->xbutton.state); + return True; + } else if (event->xany.type == MotionNotify && bp->button_down_p) { @@ -398,7 +391,7 @@ load_textures (ModeInfo *mi) } -void +ENTRYPOINT void init_toasters (ModeInfo *mi) { toaster_configuration *bp; @@ -459,9 +452,7 @@ init_toasters (ModeInfo *mi) for (i = 0; i < countof(all_objs); i++) { - struct gllist *gll = *all_objs[i]; - if (wire) - gll->primitive = GL_LINE_LOOP; + const struct gllist *gll = *all_objs[i]; glNewList (bp->dlists[i], GL_COMPILE); @@ -562,7 +553,7 @@ init_toasters (ModeInfo *mi) glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, shiny); } - renderList (gll); + renderList (gll, wire); glMatrixMode(GL_TEXTURE); glPopMatrix(); @@ -679,6 +670,7 @@ draw_floater (ModeInfo *mi, floater *f) { glPushMatrix(); glRotatef (180, 0, 1, 0); + glCallList (bp->dlists[BASE_TOASTER]); mi->polygon_count += (*all_objs[BASE_TOASTER])->points / 3; glPopMatrix(); @@ -789,7 +781,7 @@ draw_floater (ModeInfo *mi, floater *f) -void +ENTRYPOINT void draw_toasters (ModeInfo *mi) { toaster_configuration *bp = &bps[MI_SCREEN(mi)]; @@ -800,6 +792,8 @@ draw_toasters (ModeInfo *mi) if (!bp->glx_context) return; + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(bp->glx_context)); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix (); @@ -861,4 +855,6 @@ draw_toasters (ModeInfo *mi) glXSwapBuffers(dpy, window); } +XSCREENSAVER_MODULE_2 ("FlyingToasters", flyingtoasters, toasters) + #endif /* USE_GL */