X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fpipes.c;h=104f880be23103df37780f661cb8f04a422a710b;hb=f8cf5ac7b2f53510f80a0eaf286a25298be17bfe;hp=0b756d8a0178f067b75d583f859e77ef179a8388;hpb=447db08c956099b3b183886729108bf5b364c4b8;p=xscreensaver diff --git a/hacks/glx/pipes.c b/hacks/glx/pipes.c index 0b756d8a..104f880b 100644 --- a/hacks/glx/pipes.c +++ b/hacks/glx/pipes.c @@ -43,18 +43,15 @@ static const char sccsid[] = "@(#)pipes.c 4.07 97/11/24 xlockmore"; */ #ifdef STANDALONE -# define PROGCLASS "Pipes" -# define HACK_INIT init_pipes -# define HACK_DRAW draw_pipes -# define HACK_RESHAPE reshape_pipes -# define pipes_opts xlockmore_opts # define DEFAULTS "*delay: 10000 \n" \ "*count: 2 \n" \ "*cycles: 5 \n" \ "*size: 500 \n" \ "*showFPS: False \n" \ - "*fpsSolid: True \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 */ @@ -62,8 +59,21 @@ static const char sccsid[] = "@(#)pipes.c 4.07 97/11/24 xlockmore"; #ifdef USE_GL -#include +#ifdef HAVE_COCOA +# include "jwxyz.h" +#else +# include +# include +# include +#endif + +#ifdef HAVE_JWZGLES +# include "jwzgles.h" +#endif /* HAVE_JWZGLES */ + +#include "sphere.h" #include "buildlwo.h" +#include "teapot.h" #define DEF_FACTORY "2" #define DEF_FISHEYE "True" @@ -105,7 +115,7 @@ static OptionStruct desc[] = {"-/+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 @@ -155,10 +165,12 @@ 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; + GLuint guagehead, guageface, guagedial, guageconnector, teapot; + int teapot_polys; + int reset; GLXContext *glx_context; } pipesstruct; @@ -166,43 +178,25 @@ 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; @@ -235,14 +229,22 @@ MakeTube(ModeInfo *mi, int direction) } static void -mySphere(float radius) +mySphere(float radius, Bool wire) { +#if 0 GLUquadricObj *quadObj; quadObj = gluNewQuadric(); gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL); gluSphere(quadObj, radius, 16, 16); gluDeleteQuadric(quadObj); +#else + glPushMatrix(); + glScalef (radius, radius, radius); + glRotatef (90, 1, 0, 0); + unit_sphere (16, 16, wire); + glPopMatrix(); +#endif } static void @@ -483,33 +485,60 @@ MakeGuage(ModeInfo * mi, int newdir) return (1); } -static void -MakeShape(ModeInfo * mi, int newdir) + +static GLuint +build_teapot(ModeInfo *mi) { - switch (NRAND(2)) { - case 1: - if (!MakeGuage(mi, newdir)) - MakeTube(mi, newdir); - break; - default: - MakeValve(mi, newdir); - break; - } + pipesstruct *pp = &pipes[MI_SCREEN(mi)]; + GLuint list = glGenLists(1); + if (!list) return 0; + glNewList(list, GL_COMPILE); + pp->teapot_polys = unit_teapot (12, MI_IS_WIREFRAME(mi)); + glEndList(); + return list; } -void -reshape_pipes(ModeInfo * mi, int width, int height) + +static void +MakeTeapot(ModeInfo * mi, int newdir) { - pipesstruct *pp = &pipes[MI_SCREEN(mi)]; + pipesstruct *pp = &pipes[MI_SCREEN(mi)]; + + switch (newdir) { + case dirUP: + case dirDOWN: + glRotatef(90.0, 1.0, 0.0, 0.0); + glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0); + break; + case dirLEFT: + case dirRIGHT: + glRotatef(90.0, 0.0, -1.0, 0.0); + glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0); + break; + case dirNEAR: + case dirFAR: + glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0); + break; + } + + glCallList(pp->teapot); + mi->polygon_count += pp->teapot_polys; + glFrontFace(GL_CCW); +} - 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); +static void +MakeShape(ModeInfo * mi, int newdir) +{ + int n = NRAND(100); + if (n < 50) { + if (!MakeGuage(mi, newdir)) + MakeTube(mi, newdir); + } else if (n < 98) { + MakeValve(mi, newdir); + } else { + MakeTeapot(mi,newdir); + } } static void @@ -522,7 +551,6 @@ pinit(ModeInfo * mi, int zera) mi->polygon_count = 0; glClearDepth(1.0); - glClearColor(0.0, 0.0, 0.0, 1.0); glColor3f(1.0, 1.0, 1.0); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); @@ -631,8 +659,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; @@ -644,6 +688,11 @@ init_pipes(ModeInfo * mi) } pp = &pipes[screen]; +#ifdef HAVE_JWZGLES + /* Single-buffering on iOS is so confusing! */ + dbuf_p = True; +#endif + pp->window = MI_WINDOW(mi); if ((pp->glx_context = init_GL(mi)) != NULL) { @@ -666,6 +715,7 @@ init_pipes(ModeInfo * mi) pp->guageface = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageFace); pp->guagedial = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageDial); pp->guageconnector = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageConnector); + pp->teapot = build_teapot(mi); } /* else they are all 0, thanks to calloc(). */ @@ -693,13 +743,14 @@ init_pipes(ModeInfo * mi) } } -void -draw_pipes(ModeInfo * mi) +ENTRYPOINT void +draw_pipes (ModeInfo * mi) { pipesstruct *pp = &pipes[MI_SCREEN(mi)]; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); + Bool wire = MI_IS_WIREFRAME(mi); int newdir; int OPX, OPY, OPZ; @@ -707,6 +758,17 @@ draw_pipes(ModeInfo * mi) if (!pp->glx_context) return; + 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); + } + glPushMatrix(); glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8); @@ -728,7 +790,7 @@ draw_pipes(ModeInfo * mi) if (pp->olddir == dirNone) { glPushMatrix(); glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0); - mySphere(0.6); + mySphere(0.6, wire); glPopMatrix(); } /* Check for stop conditions */ @@ -736,16 +798,16 @@ draw_pipes(ModeInfo * mi) glPushMatrix(); 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); + mySphere(0.6, wire); 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) { - if (!mi->fps_p) - 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) ? MI_PAUSE(mi) : 100); } else { pinit(mi, 0); } @@ -799,7 +861,7 @@ draw_pipes(ModeInfo * mi) switch (sysT) { case 1: glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0); - mySphere(elbowradius); + mySphere(elbowradius, wire); break; case 2: case 3: @@ -974,14 +1036,15 @@ draw_pipes(ModeInfo * mi) glFlush(); + if (mi->fps_p) do_fps (mi); + 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)]; @@ -991,9 +1054,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; @@ -1026,6 +1091,8 @@ release_pipes(ModeInfo * mi) glDeleteLists(pp->guagedial, 1); if (pp->guageconnector) glDeleteLists(pp->guageconnector, 1); + if (pp->teapot) + glDeleteLists(pp->teapot, 1); } } @@ -1035,4 +1102,6 @@ release_pipes(ModeInfo * mi) FreeAllGL(mi); } +XSCREENSAVER_MODULE ("Pipes", pipes) + #endif