X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fglplanet.c;h=d5d3de48adc166254e19b81f5d933149f9c96e7a;hb=82c5080773aae5e72ec155327c075775e023d2ee;hp=f7d02557b4f6c1ae96cc6eae9182ae23fcd6d3f6;hpb=06e9a7886a77cad92f9ddbc169d6d199a4d8b76d;p=xscreensaver diff --git a/hacks/glx/glplanet.c b/hacks/glx/glplanet.c index f7d02557..d5d3de48 100644 --- a/hacks/glx/glplanet.c +++ b/hacks/glx/glplanet.c @@ -1,12 +1,6 @@ /* -*- Mode: C; tab-width: 4 -*- */ -/* glplanet --- 3D rotating planet, e.g., Earth. */ - -#if !defined( lint ) && !defined( SABER ) -static const char sccsid[] = "@(#)plate.c 4.07 97/11/24 xlockmore"; - -#endif - -/*- +/* glplanet --- 3D rotating planet, e.g., Earth. + * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, * provided that the above copyright notice appear in all copies and that @@ -20,6 +14,8 @@ static const char sccsid[] = "@(#)plate.c 4.07 97/11/24 xlockmore"; * other special, indirect and consequential damages. * * Revision History: + * 21-Mar-01: jwz@jwz.org Broke sphere routine out into its own file. + * * 9-Oct-98: dek@cgl.ucsf.edu Added stars. * * 8-Oct-98: jwz@jwz.org Made the 512x512x1 xearth image be built in. @@ -58,8 +54,10 @@ static const char sccsid[] = "@(#)plate.c 4.07 97/11/24 xlockmore"; # define PROGCLASS "Planet" # define HACK_INIT init_planet # define HACK_DRAW draw_planet +# define HACK_RESHAPE reshape_planet # define planet_opts xlockmore_opts #define DEFAULTS "*delay: 15000 \n" \ + "*showFPS: False \n" \ "*rotate: True \n" \ "*roll: True \n" \ "*bounce: True \n" \ @@ -78,6 +76,8 @@ static const char sccsid[] = "@(#)plate.c 4.07 97/11/24 xlockmore"; #ifdef USE_GL /* whole file */ +#include "sphere.h" + #ifdef HAVE_XPM # include # ifndef PIXEL_ALREADY_TYPEDEFED @@ -161,8 +161,8 @@ ModStruct planet_description = */ #define NUM_STARS 1000 -#define SLICES 15 -#define STACKS 15 +#define SLICES 32 +#define STACKS 32 /* radius of the sphere- fairly arbitrary */ #define RADIUS 4 @@ -237,8 +237,10 @@ setup_xbm_texture (char *bits, int width, int height, *out++ = (word & 0x0000FF); } + clear_gl_error(); glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); + check_gl_error("texture"); /* setup parameters for texturing */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); @@ -266,9 +268,11 @@ setup_file_texture (ModeInfo *mi, char *filename) { XImage *image = xpm_to_ximage (dpy, visual, cmap, xpm_data); + clear_gl_error(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->data); + check_gl_error("texture"); /* setup parameters for texturing */ glPixelStorei(GL_UNPACK_ALIGNMENT, 4); @@ -372,6 +376,7 @@ setup_face(void) } +#if 0 /* Function for determining points on the surface of the sphere */ static void inline ParametricSphere(float theta, float rho, GLfloat *vector) { @@ -387,6 +392,7 @@ static void inline ParametricSphere(float theta, float rho, GLfloat *vector) return; } +#endif /* lame way to generate some random stars */ @@ -446,14 +452,6 @@ pinit(ModeInfo * mi) { Bool wire = MI_IS_WIREFRAME(mi); planetstruct *gp = &planets[MI_SCREEN(mi)]; - int i, j; - int stacks=STACKS, slices=SLICES; - float radius=RADIUS; - - float drho, dtheta; - float rho, theta; - GLfloat vector[3]; - GLfloat ds, dt, t, s;; if (wire) { glEnable(GL_LINE_SMOOTH); @@ -473,71 +471,13 @@ pinit(ModeInfo * mi) generate_stars(MI_WIDTH(mi), MI_HEIGHT(mi)); } - - /*- - * Generate a sphere with quadrilaterals. - * Quad vertices are determined using a parametric sphere function. - * For fun, you could generate practically any parameteric surface and - * map an image onto it. - */ - - drho = M_PI / stacks; - dtheta = 2.0 * M_PI / slices; - ds = 1.0 / slices; - dt = 1.0 / stacks; - - gp->platelist=glGenLists(1); glNewList(gp->platelist, GL_COMPILE); - - glColor3f(1,1,1); - glBegin( wire ? GL_LINE_LOOP : GL_QUADS ); - - t = 0.0; - for(i=0; ixpos += gp->dx; - gp->ypos += gp->dy; - gp->zpos += gp->dz; - - /* Bounce. */ - if (gp->xpos > gp->box_depth) - gp->xpos = gp->box_depth, gp->dx = -gp->dx; - else if (gp->xpos < 0) - gp->xpos = 0, gp->dx = -gp->dx; - - if (gp->ypos > gp->box_width/2) - gp->ypos = gp->box_width/2, gp->dy = -gp->dy; - else if (gp->ypos < -gp->box_width/2) - gp->ypos = -gp->box_width/2, gp->dy = -gp->dy; - - if (gp->zpos > gp->box_height/2) - gp->zpos = gp->box_height/2, gp->dz = -gp->dz; - else if (gp->zpos < -gp->box_height/2) - gp->zpos = -gp->box_height/2, gp->dz = -gp->dz; + static int frame = 0; +# define SINOID(SCALE,SIZE) \ + ((((1 + sin((frame * (SCALE)) / 2 * M_PI)) / 2.0) * (SIZE)) - (SIZE)/2) + gp->xpos = SINOID(0.031, gp->box_width); + gp->ypos = SINOID(0.023, gp->box_height); + gp->zpos = SINOID(0.017, gp->box_depth); + frame++; } } /* Standard reshape function */ -static void -reshape(int width, int height) +void +reshape_planet(ModeInfo *mi, int width, int height) { GLfloat light[4]; GLfloat h = (GLfloat) height / (GLfloat) width; @@ -711,7 +638,7 @@ init_planet(ModeInfo * mi) gp->window = MI_WINDOW(mi); if ((gp->glx_context = init_GL(mi)) != NULL) { - reshape(MI_WIDTH(mi), MI_HEIGHT(mi)); + reshape_planet(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); pinit(mi); } else { MI_CLEARWINDOW(mi); @@ -768,6 +695,7 @@ draw_planet(ModeInfo * mi) + if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(display, window);