X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fglplanet.c;h=047abbf6c5ba61daa61fc9eef9b95c56d26c1ef7;hb=8eb2873d7054e705c4e83f22d18c40946a9e2529;hp=58807895bf4c740b9cb2e36d707fda41d1c460e2;hpb=3d9140a05b5272fed0883a0af0a71e30ef44d47f;p=xscreensaver diff --git a/hacks/glx/glplanet.c b/hacks/glx/glplanet.c index 58807895..047abbf6 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. @@ -80,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 @@ -378,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) { @@ -393,20 +392,19 @@ static void inline ParametricSphere(float theta, float rho, GLfloat *vector) return; } +#endif /* lame way to generate some random stars */ void generate_stars(int width, int height) { - int i; -/* GLfloat size_range[2], size;*/ - GLfloat x, y; + int i, j; + int max_size = 3; + GLfloat inc = 0.5; + int steps = max_size / inc; planetstruct *gp = &planets[MI_SCREEN(mi)]; -/* glGetFloatv(GL_POINT_SIZE_RANGE, size_range); */ - -/* printf("size range: %f\t%f\n", size_range[0], size_range[1]); */ gp->starlist = glGenLists(1); glNewList(gp->starlist, GL_COMPILE); @@ -421,20 +419,27 @@ void generate_stars(int width, int height) /* disable depth testing for the stars, so they don't obscure the planet */ glDisable(GL_DEPTH_TEST); - glEnable(GL_POINT_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBegin(GL_POINTS); - for(i = 0 ; i < NUM_STARS ; i++) - { -/* size = ((random()%size_range[0])) * size_range[1]/2.; */ -/* glPointSize(size); */ - x = random() % width; - y = random() % height; - glVertex2f(x,y); - } - glEnd(); + glColor3f(1,1,1); + + glEnable(GL_POINT_SMOOTH); + + for (j = 1; j <= steps; j++) + { + glPointSize(inc * j); + glBegin(GL_POINTS); + for(i = 0 ; i < NUM_STARS / steps; i++) + { + glColor3f (0.6 + frand(0.3), + 0.6 + frand(0.3), + 0.6 + frand(0.3)); + glVertex2f ((GLfloat) (random() % width), + (GLfloat) (random() % height)); + } + glEnd(); + } /* return to original PROJECT and MODELVIEW */ glMatrixMode(GL_PROJECTION); @@ -446,20 +451,26 @@ void generate_stars(int width, int height) } +/* Set up lighting */ +static void +init_sun (ModeInfo * mi) +{ + GLfloat light[4]; + light[0] = frand(2.0) - 1.0; + light[1] = frand(2.0) - 1.0; + light[2] = 1.0; + light[3] = 0; + + glLightfv(GL_LIGHT0, GL_POSITION, light); +} + + /* Initialization function for screen saver */ static void 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); @@ -479,72 +490,16 @@ 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; istarlist); - - } + glCallList(gp->starlist); glPopMatrix(); - glPopAttrib(); } /* protect our modelview matrix and attributes */