X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fglx%2Fpipes.c;h=e47361eaaaf8a1e0fffdacbd1fe3ee4ec8049e4a;hp=c165a748b63e5232830519c2b8120a5d66272486;hb=07faf451b99879183ed7e909e43a0e065be1ee7f;hpb=2a991a811de4c7b22f812682b267b616a809fd9a diff --git a/hacks/glx/pipes.c b/hacks/glx/pipes.c index c165a748..e47361ea 100644 --- a/hacks/glx/pipes.c +++ b/hacks/glx/pipes.c @@ -1,9 +1,8 @@ /* -*- Mode: C; tab-width: 4 -*- */ /* pipes --- 3D selfbuiding pipe system */ -#if !defined( lint ) && !defined( SABER ) +#if 0 static const char sccsid[] = "@(#)pipes.c 4.07 97/11/24 xlockmore"; - #endif /*- @@ -33,10 +32,7 @@ static const char sccsid[] = "@(#)pipes.c 4.07 97/11/24 xlockmore"; * Since I'm not a native English speaker, my apologies for any grammatical * mistake. * - * My e-mail addresses are - * - * vianna@cat.cbpf.br - * and + * My e-mail address is * m-vianna@usa.net * Marcelo F. Vianna (Apr-09-1997) * @@ -46,26 +42,15 @@ static const char sccsid[] = "@(#)pipes.c 4.07 97/11/24 xlockmore"; * 29-Apr-97: Efficiency speed-ups by Marcelo F. Vianna */ -/*- - * due to a Bug/feature in VMS X11/Intrinsic.h has to be placed before xlock. - * otherwise caddr_t is not defined correctly - */ - -#include - #ifdef STANDALONE -# define PROGCLASS "Pipes" -# define HACK_INIT init_pipes -# define HACK_DRAW draw_pipes -# define pipes_opts xlockmore_opts -# define DEFAULTS "*delay: 100 \n" \ +# define DEFAULTS "*delay: 10000 \n" \ "*count: 2 \n" \ "*cycles: 5 \n" \ "*size: 500 \n" \ - "*fisheye: True \n" \ - "*tightturns: False \n" \ - "*rotatepipes: True \n" \ - "*noBuffer: True \n" + "*showFPS: False \n" \ + "*fpsSolid: True \n" +# define refresh_pipes 0 +# define pipes_handle_event 0 # include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ @@ -73,54 +58,55 @@ static const char sccsid[] = "@(#)pipes.c 4.07 97/11/24 xlockmore"; #ifdef USE_GL -#include #include "buildlwo.h" #define DEF_FACTORY "2" #define DEF_FISHEYE "True" #define DEF_TIGHTTURNS "False" #define DEF_ROTATEPIPES "True" +#define DEF_DBUF "False" #define NofSysTypes 3 static int factory; static Bool fisheye, tightturns, rotatepipes; +static Bool dbuf_p; static XrmOptionDescRec opts[] = { - {"-factory", ".pipes.factory", XrmoptionSepArg, (caddr_t) NULL}, - {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "on"}, - {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "off"}, - {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "on"}, - {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "off"}, - {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "on"}, - {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "off"} + {"-factory", ".pipes.factory", XrmoptionSepArg, 0}, + {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, "on"}, + {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, "off"}, + {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, "on"}, + {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, "off"}, + {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "on"}, + {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "off"}, + {"-db", ".pipes.doubleBuffer", XrmoptionNoArg, "on"}, + {"+db", ".pipes.doubleBuffer", XrmoptionNoArg, "off"}, }; static argtype vars[] = { - {(caddr_t *) & factory, "factory", "Factory", DEF_FACTORY, t_Int}, - {(caddr_t *) & fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool}, - {(caddr_t *) & tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool}, - {(caddr_t *) & rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool} + {&factory, "factory", "Factory", DEF_FACTORY, t_Int}, + {&fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool}, + {&tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool}, + {&rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool}, + {&dbuf_p, "doubleBuffer", "DoubleBuffer", DEF_DBUF, t_Bool} }; static OptionStruct desc[] = { {"-factory num", "how much extra equipment in pipes (0 for none)"}, {"-/+fisheye", "turn on/off zoomed-in view of pipes"}, {"-/+tightturns", "turn on/off tight turns"}, - {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"} + {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"}, + {"-/+db", "turn on/off double buffering"} }; -ModeSpecOpt pipes_opts = +ENTRYPOINT ModeSpecOpt pipes_opts = {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc}; #ifdef USE_MODULES ModStruct pipes_description = {"pipes", "init_pipes", "draw_pipes", "release_pipes", -#if defined( MESA ) && defined( SLOW ) "draw_pipes", -#else - "change_pipes", -#endif "change_pipes", NULL, &pipes_opts, 1000, 2, 5, 500, 4, 1.0, "", "Shows a selfbuilding pipe system", 0, NULL}; @@ -148,9 +134,8 @@ ModStruct pipes_description = /*************************************************************************/ typedef struct { -#if defined( MESA ) && defined( SLOW ) int flip; -#endif + GLint WindH, WindW; int Cells[HCELLS][VCELLS][HCELLS]; int usedcolors[DEFINEDCOLORS]; @@ -165,10 +150,11 @@ typedef struct { int system_length; int turncounter; Window window; - float *system_color; + const float *system_color; GLfloat initial_rotation; GLuint valve, bolts, betweenbolts, elbowbolts, elbowcoins; GLuint guagehead, guageface, guagedial, guageconnector; + int reset; GLXContext *glx_context; } pipesstruct; @@ -176,49 +162,31 @@ extern struct lwo LWO_BigValve, LWO_PipeBetweenBolts, LWO_Bolts3D; extern struct lwo LWO_GuageHead, LWO_GuageFace, LWO_GuageDial, LWO_GuageConnector; extern struct lwo LWO_ElbowBolts, LWO_ElbowCoins; -static float front_shininess[] = -{60.0}; -static float front_specular[] = -{0.7, 0.7, 0.7, 1.0}; -static float ambient0[] = -{0.4, 0.4, 0.4, 1.0}; -static float diffuse0[] = -{1.0, 1.0, 1.0, 1.0}; -static float ambient1[] = -{0.2, 0.2, 0.2, 1.0}; -static float diffuse1[] = -{0.5, 0.5, 0.5, 1.0}; -static float position0[] = -{1.0, 1.0, 1.0, 0.0}; -static float position1[] = -{-1.0, -1.0, 1.0, 0.0}; -static float lmodel_ambient[] = -{0.5, 0.5, 0.5, 1.0}; -static float lmodel_twoside[] = -{GL_TRUE}; - -static float MaterialRed[] = -{0.7, 0.0, 0.0, 1.0}; -static float MaterialGreen[] = -{0.1, 0.5, 0.2, 1.0}; -static float MaterialBlue[] = -{0.0, 0.0, 0.7, 1.0}; -static float MaterialCyan[] = -{0.2, 0.5, 0.7, 1.0}; -static float MaterialYellow[] = -{0.7, 0.7, 0.0, 1.0}; -static float MaterialMagenta[] = -{0.6, 0.2, 0.5, 1.0}; -static float MaterialWhite[] = -{0.7, 0.7, 0.7, 1.0}; -static float MaterialGray[] = -{0.2, 0.2, 0.2, 1.0}; +static const float front_shininess[] = {60.0}; +static const float front_specular[] = {0.7, 0.7, 0.7, 1.0}; +static const float ambient0[] = {0.4, 0.4, 0.4, 1.0}; +static const float diffuse0[] = {1.0, 1.0, 1.0, 1.0}; +static const float ambient1[] = {0.2, 0.2, 0.2, 1.0}; +static const float diffuse1[] = {0.5, 0.5, 0.5, 1.0}; +static const float position0[] = {1.0, 1.0, 1.0, 0.0}; +static const float position1[] = {-1.0, -1.0, 1.0, 0.0}; +static const float lmodel_ambient[] = {0.5, 0.5, 0.5, 1.0}; +static const float lmodel_twoside[] = {GL_TRUE}; + +static const float MaterialRed[] = {0.7, 0.0, 0.0, 1.0}; +static const float MaterialGreen[] = {0.1, 0.5, 0.2, 1.0}; +static const float MaterialBlue[] = {0.0, 0.0, 0.7, 1.0}; +static const float MaterialCyan[] = {0.2, 0.5, 0.7, 1.0}; +static const float MaterialYellow[] = {0.7, 0.7, 0.0, 1.0}; +static const float MaterialMagenta[] = {0.6, 0.2, 0.5, 1.0}; +static const float MaterialWhite[] = {0.7, 0.7, 0.7, 1.0}; +static const float MaterialGray[] = {0.2, 0.2, 0.2, 1.0}; static pipesstruct *pipes = NULL; static void -MakeTube(int direction) +MakeTube(ModeInfo *mi, int direction) { float an; float SINan_3, COSan_3; @@ -239,6 +207,7 @@ MakeTube(int direction) glNormal3f((COSan_3 = cos(an) / 3.0), (SINan_3 = sin(an) / 3.0), 0.0); glVertex3f(COSan_3, SINan_3, one_third); glVertex3f(COSan_3, SINan_3, -one_third); + mi->polygon_count++; } glEnd(); } @@ -319,6 +288,7 @@ myElbow(ModeInfo * mi, int bolted) glVertex3fv(p1); glNormal3fv(n0); glVertex3fv(p0); + mi->polygon_count++; glEnd(); } } @@ -331,8 +301,10 @@ myElbow(ModeInfo * mi, int bolted) glRotatef(90.0, 0.0, 1.0, 0.0); glTranslatef(0.0, one_third, one_third); glCallList(pp->elbowcoins); + mi->polygon_count += LWO_ElbowCoins.num_pnts/3; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray); glCallList(pp->elbowbolts); + mi->polygon_count += LWO_ElbowBolts.num_pnts/3; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color); glPopMatrix(); glFrontFace(GL_CCW); @@ -404,8 +376,10 @@ MakeValve(ModeInfo * mi, int newdir) } glFrontFace(GL_CW); glCallList(pp->betweenbolts); + mi->polygon_count += LWO_PipeBetweenBolts.num_pnts/3; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray); glCallList(pp->bolts); + mi->polygon_count += LWO_Bolts3D.num_pnts/3; if (!MI_IS_MONO(mi)) { if (pp->system_color == MaterialRed) { glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialYellow : MaterialBlue); @@ -428,6 +402,7 @@ MakeValve(ModeInfo * mi, int newdir) } glRotatef((GLfloat) (NRAND(90)), 1.0, 0.0, 0.0); glCallList(pp->valve); + mi->polygon_count += LWO_BigValve.num_pnts/3; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color); glFrontFace(GL_CCW); } @@ -453,11 +428,14 @@ MakeGuage(ModeInfo * mi, int newdir) if ((newdir == dirLEFT) || (newdir == dirRIGHT)) glRotatef(90.0, 0.0, 1.0, 0.0); glCallList(pp->betweenbolts); + mi->polygon_count += LWO_PipeBetweenBolts.num_pnts/3; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray); glCallList(pp->bolts); + mi->polygon_count += LWO_Bolts3D.num_pnts/3; glPopMatrix(); glCallList(pp->guageconnector); + mi->polygon_count += LWO_GuageConnector.num_pnts/3; glPushMatrix(); glTranslatef(0.0, 1.33333, 0.0); /* Do not change the above to 1 + ONE_THIRD, because */ @@ -465,14 +443,17 @@ MakeGuage(ModeInfo * mi, int newdir) glRotatef(NRAND(270) + 45.0, 0.0, 0.0, -1.0); /* Random rotation for the dial. I love it. */ glCallList(pp->guagedial); + mi->polygon_count += LWO_GuageDial.num_pnts/3; glPopMatrix(); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color); glCallList(pp->guagehead); + mi->polygon_count += LWO_GuageHead.num_pnts/3; /* GuageFace is drawn last, in case of low-res depth buffers. */ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialWhite); glCallList(pp->guageface); + mi->polygon_count += LWO_GuageFace.num_pnts/3; glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color); glFrontFace(GL_CCW); @@ -486,7 +467,7 @@ MakeShape(ModeInfo * mi, int newdir) switch (NRAND(2)) { case 1: if (!MakeGuage(mi, newdir)) - MakeTube(newdir); + MakeTube(mi, newdir); break; default: MakeValve(mi, newdir); @@ -494,25 +475,15 @@ MakeShape(ModeInfo * mi, int newdir) } } -static void -reshape(ModeInfo * mi, int width, int height) -{ - pipesstruct *pp = &pipes[MI_SCREEN(mi)]; - - glViewport(0, 0, pp->WindW = (GLint) width, pp->WindH = (GLint) height); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */ - gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0); - glMatrixMode(GL_MODELVIEW); -} - static void pinit(ModeInfo * mi, int zera) { pipesstruct *pp = &pipes[MI_SCREEN(mi)]; int X, Y, Z; + if (zera) + mi->polygon_count = 0; + glClearDepth(1.0); glClearColor(0.0, 0.0, 0.0, 1.0); glColor3f(1.0, 1.0, 1.0); @@ -538,7 +509,7 @@ pinit(ModeInfo * mi, int zera) if (zera) { pp->system_number = 1; - glDrawBuffer(GL_FRONT_AND_BACK); + glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); (void) memset(pp->Cells, 0, sizeof (pp->Cells)); for (X = 0; X < HCELLS; X++) { @@ -623,8 +594,24 @@ pinit(ModeInfo * mi, int zera) pp->nowdir = SelectNeighbor(mi); } -void -init_pipes(ModeInfo * mi) +ENTRYPOINT void +reshape_pipes(ModeInfo * mi, int width, int height) +{ + pipesstruct *pp = &pipes[MI_SCREEN(mi)]; + pinit(mi, 1); + + glViewport(0, 0, pp->WindW = (GLint) width, pp->WindH = (GLint) height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */ + gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0); + glMatrixMode(GL_MODELVIEW); + + glClear(GL_COLOR_BUFFER_BIT); +} + +ENTRYPOINT void +init_pipes (ModeInfo * mi) { int screen = MI_SCREEN(mi); pipesstruct *pp; @@ -639,7 +626,7 @@ init_pipes(ModeInfo * mi) pp->window = MI_WINDOW(mi); if ((pp->glx_context = init_GL(mi)) != NULL) { - reshape(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); + reshape_pipes(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); if (rotatepipes) pp->initial_rotation = NRAND(180); /* jwz */ else @@ -685,8 +672,8 @@ init_pipes(ModeInfo * mi) } } -void -draw_pipes(ModeInfo * mi) +ENTRYPOINT void +draw_pipes (ModeInfo * mi) { pipesstruct *pp = &pipes[MI_SCREEN(mi)]; @@ -699,13 +686,17 @@ draw_pipes(ModeInfo * mi) if (!pp->glx_context) return; - glXMakeCurrent(display, window, *(pp->glx_context)); + glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context)); + + if (pp->reset) { + if (--pp->reset) { + /* Would be nice to fade to black here, by drawing successive quads + over the whole scene with gamma. */ + return; + } + pinit(mi, 1); + } -#if defined( MESA ) && defined( SLOW ) - glDrawBuffer(GL_BACK); -#else - glDrawBuffer(GL_FRONT); -#endif glPushMatrix(); glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8); @@ -736,16 +727,15 @@ draw_pipes(ModeInfo * mi) glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0); /* Finish the system with another sphere */ mySphere(0.6); -#if defined( MESA ) && defined( SLOW ) - glXSwapBuffers(display, window); -#endif + glPopMatrix(); /* If the maximum number of system was drawn, restart (clearing the screen), */ /* else start a new system. */ if (++pp->system_number > pp->number_of_systems) { - (void) sleep(1); - pinit(mi, 1); + /* pause doing nothing for N seconds before clearing the screen. */ + int secs = 3; + pp->reset = secs * 1000000 / MI_PAUSE(mi); } else { pinit(mi, 0); } @@ -784,7 +774,7 @@ draw_pipes(ModeInfo * mi) if ((pp->counter > 1) && (NRAND(100) < factory)) { MakeShape(mi, newdir); } else { - MakeTube(newdir); + MakeTube(mi, newdir); } glPopMatrix(); } else { @@ -968,21 +958,21 @@ draw_pipes(ModeInfo * mi) /* Cells'face pipe */ glTranslatef(((pp->PX + OPX) / 2.0 - 16) / 3.0 * 4.0, ((pp->PY + OPY) / 2.0 - 12) / 3.0 * 4.0, ((pp->PZ + OPZ) / 2.0 - 16) / 3.0 * 4.0); - MakeTube(newdir); + MakeTube(mi, newdir); glPopMatrix(); glFlush(); -#if defined( MESA ) && defined( SLOW ) - pp->flip = !pp->flip; - if (pp->flip) - glXSwapBuffers(display, window); -#endif + if (dbuf_p) + glXSwapBuffers(display, window); + + if (mi->fps_p) do_fps (mi); } -void -change_pipes(ModeInfo * mi) +#ifndef STANDALONE +ENTRYPOINT void +change_pipes (ModeInfo * mi) { pipesstruct *pp = &pipes[MI_SCREEN(mi)]; @@ -992,9 +982,11 @@ change_pipes(ModeInfo * mi) glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context)); pinit(mi, 1); } +#endif /* !STANDALONE */ -void -release_pipes(ModeInfo * mi) + +ENTRYPOINT void +release_pipes (ModeInfo * mi) { if (pipes != NULL) { int screen; @@ -1036,4 +1028,6 @@ release_pipes(ModeInfo * mi) FreeAllGL(mi); } +XSCREENSAVER_MODULE ("Pipes", pipes) + #endif