X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fpulsar.c;h=869933b6e24a4c89e11935b5d062eaf87187a4fa;hb=39809ded547bdbb08207d3e514950425215b4410;hp=f4535670bf7250c0d1ebd70326b1b07da55a8fd4;hpb=6a1da724858673ac40aa13a9612340d8bed8c7b9;p=xscreensaver diff --git a/hacks/glx/pulsar.c b/hacks/glx/pulsar.c index f4535670..869933b6 100644 --- a/hacks/glx/pulsar.c +++ b/hacks/glx/pulsar.c @@ -1,5 +1,5 @@ /* -*- Mode: C; tab-width: 4 -*- */ -/* pulsar --- pulsar module for xscreensaver */ +/* pulsar --- pulsar module for xpulsar */ /*- * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, @@ -20,7 +20,7 @@ * 4-May-1999: dek@cgl.ucsf.edu Submitted module "pulsar" updates * * Notes: - * The pulsar screensaver draws a number of rotating, pulsing rectangles + * The pulsar pulsar draws a number of rotating, pulsing rectangles * on your screen. Depending on the options you choose, you can set a number * of interesting OpenGL parameters, including alpha blending, depth testing, fog, * lighting, texturing, mipmapping, bilinear filtering, and line antialiasing. @@ -40,34 +40,13 @@ #include #include -/*- - * 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 "Screensaver" -# define HACK_INIT init_screensaver -# define HACK_DRAW draw_screensaver -# define HACK_RESHAPE reshape_screensaver -# define screensaver_opts xlockmore_opts #define DEFAULTS "*delay: 10000 \n" \ "*showFPS: False \n" \ - "*light: False \n" \ - "*wire: False \n" \ - "*quads: 5 \n" \ - "*blend: True \n" \ - "*fog: False \n" \ - "*antialias: False \n" \ - "*texture: False \n" \ - "*texture_quality: False \n" \ - "*mipmap: False \n" \ - "*doDepth: False \n" \ - "*image: BUILTIN \n" - -# include "xlockmore.h" /* from the xscreensaver distribution */ + +# define release_pulsar 0 +# define pulsar_handle_event xlockmore_no_events +# include "xlockmore.h" /* from the xpulsar distribution */ #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ #endif /* !STANDALONE */ @@ -82,14 +61,6 @@ # endif /* VMS */ #endif - -#include -#include - -#include -#include -#include - #include "xpm-ximage.h" /* Functions for loading and storing textures */ @@ -98,7 +69,6 @@ #define checkImageHeight 64 /* Functions for handling the frames per second timer */ -#include "GL/glx.h" #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) @@ -107,7 +77,7 @@ #define HEIGHT 600 #define NUM_QUADS 5 -#define DEF_NUM_QUADS "5" +#define DEF_QUADS "5" #define DEF_LIGHT "False" #define DEF_WIRE "False" #define DEF_BLEND "True" @@ -133,41 +103,41 @@ static char *which_image; static XrmOptionDescRec opts[] = { - {"-quads", ".pulsar.quads", XrmoptionSepArg, (caddr_t) NULL }, - {"-light", ".pulsar.light", XrmoptionNoArg, (caddr_t) "true" }, - {"+light", ".pulsar.light", XrmoptionNoArg, (caddr_t) "false" }, - {"-wire", ".pulsar.wire", XrmoptionNoArg, (caddr_t) "true" }, - {"+wire", ".pulsar.wire", XrmoptionNoArg, (caddr_t) "false" }, - {"-blend", ".pulsar.blend", XrmoptionNoArg, (caddr_t) "true" }, - {"+blend", ".pulsar.blend", XrmoptionNoArg, (caddr_t) "false" }, - {"-fog", ".pulsar.fog", XrmoptionNoArg, (caddr_t) "true" }, - {"+fog", ".pulsar.fog", XrmoptionNoArg, (caddr_t) "false" }, - {"-antialias", ".pulsar.antialias", XrmoptionNoArg, (caddr_t) "true" }, - {"+antialias", ".pulsar.antialias", XrmoptionNoArg, (caddr_t) "false" }, - {"-texture", ".pulsar.texture", XrmoptionNoArg, (caddr_t) "true" }, - {"+texture", ".pulsar.texture", XrmoptionNoArg, (caddr_t) "false" }, - {"-texture_quality", ".pulsar.texture_quality", XrmoptionNoArg, (caddr_t) "true" }, - {"+texture_quality", ".pulsar.texture_quality", XrmoptionNoArg, (caddr_t) "false" }, - {"-mipmap", ".pulsar.mipmap", XrmoptionNoArg, (caddr_t) "true" }, - {"+mipmap", ".pulsar.mipmap", XrmoptionNoArg, (caddr_t) "false" }, - {"-do_depth", ".pulsar.doDepth", XrmoptionNoArg, (caddr_t) "true" }, - {"+do_depth", ".pulsar.doDepth", XrmoptionNoArg, (caddr_t) "false" }, - {"-image", ".pulsar.image", XrmoptionSepArg, (caddr_t) NULL }, + {"-quads", ".pulsar.quads", XrmoptionSepArg, 0 }, + {"-light", ".pulsar.light", XrmoptionNoArg, "true" }, + {"+light", ".pulsar.light", XrmoptionNoArg, "false" }, + {"-wire", ".pulsar.wire", XrmoptionNoArg, "true" }, + {"+wire", ".pulsar.wire", XrmoptionNoArg, "false" }, + {"-blend", ".pulsar.blend", XrmoptionNoArg, "true" }, + {"+blend", ".pulsar.blend", XrmoptionNoArg, "false" }, + {"-fog", ".pulsar.fog", XrmoptionNoArg, "true" }, + {"+fog", ".pulsar.fog", XrmoptionNoArg, "false" }, + {"-antialias", ".pulsar.antialias", XrmoptionNoArg, "true" }, + {"+antialias", ".pulsar.antialias", XrmoptionNoArg, "false" }, + {"-texture", ".pulsar.texture", XrmoptionNoArg, "true" }, + {"+texture", ".pulsar.texture", XrmoptionNoArg, "false" }, + {"-texture_quality", ".pulsar.textureQuality", XrmoptionNoArg, "true" }, + {"+texture_quality", ".pulsar.textureQuality", XrmoptionNoArg, "false" }, + {"-mipmap", ".pulsar.mipmap", XrmoptionNoArg, "true" }, + {"+mipmap", ".pulsar.mipmap", XrmoptionNoArg, "false" }, + {"-do_depth", ".pulsar.doDepth", XrmoptionNoArg, "true" }, + {"+do_depth", ".pulsar.doDepth", XrmoptionNoArg, "false" }, + {"-image", ".pulsar.image", XrmoptionSepArg, 0 }, }; static argtype vars[] = { - {(caddr_t *) &num_quads, "quads", "Quads", DEF_NUM_QUADS, t_Int}, - {(caddr_t *) &do_light, "light", "Light", DEF_LIGHT, t_Bool}, - {(caddr_t *) &do_wire, "wire", "Wire", DEF_WIRE, t_Bool}, - {(caddr_t *) &do_blend, "blend", "Blend", DEF_BLEND, t_Bool}, - {(caddr_t *) &do_fog, "fog", "Fog", DEF_FOG, t_Bool}, - {(caddr_t *) &do_antialias, "antialias", "Antialias", DEF_ANTIALIAS, t_Bool}, - {(caddr_t *) &do_texture, "texture", "Texture", DEF_TEXTURE, t_Bool}, - {(caddr_t *) &do_texture_quality, "texture_quality", "Texture_quality", DEF_TEXTURE_QUALITY, t_Bool}, - {(caddr_t *) &do_mipmap, "mipmap", "Mipmap", DEF_MIPMAP, t_Bool}, - {(caddr_t *) &do_depth, "doDepth", "DoDepth", DEF_DO_DEPTH, t_Bool}, - {(caddr_t *) &which_image, "image", "Image", DEF_IMAGE, t_String}, + {&num_quads, "quads", "Quads", DEF_QUADS, t_Int}, + {&do_light, "light", "Light", DEF_LIGHT, t_Bool}, + {&do_wire, "wire", "Wire", DEF_WIRE, t_Bool}, + {&do_blend, "blend", "Blend", DEF_BLEND, t_Bool}, + {&do_fog, "fog", "Fog", DEF_FOG, t_Bool}, + {&do_antialias, "antialias", "Antialias", DEF_ANTIALIAS, t_Bool}, + {&do_texture, "texture", "Texture", DEF_TEXTURE, t_Bool}, + {&do_texture_quality, "textureQuality", "TextureQuality", DEF_TEXTURE_QUALITY, t_Bool}, + {&do_mipmap, "mipmap", "Mipmap", DEF_MIPMAP, t_Bool}, + {&do_depth, "doDepth", "DoDepth", DEF_DO_DEPTH, t_Bool}, + {&which_image, "image", "Image", DEF_IMAGE, t_String}, }; @@ -186,27 +156,16 @@ static OptionStruct desc[] = {"-image ", "texture image to load"}, }; -ModeSpecOpt screensaver_opts = {countof(opts), opts, countof(vars), vars, desc}; +ENTRYPOINT ModeSpecOpt pulsar_opts = {countof(opts), opts, countof(vars), vars, desc}; #ifdef USE_MODULES -ModStruct screensaver_description = -{"screensaver", "init_screensaver", "draw_screensaver", "release_screensaver", - "draw_screensaver", "init_screensaver", NULL, &screensaver_opts, +ModStruct pulsar_description = +{"pulsar", "init_pulsar", "draw_pulsar", NULL, + "draw_pulsar", "init_pulsar", "free_pulsar", &pulsar_opts, 1000, 1, 2, 1, 4, 1.0, "", - "OpenGL screensaver", 0, NULL}; + "OpenGL pulsar", 0, NULL}; #endif - -/* structure for holding the screensaver data */ -typedef struct { - int screen_width, screen_height; - GLXContext *glx_context; - Window window; - XColor fg, bg; -} screensaverstruct; - -static screensaverstruct *Screensaver = NULL; - struct quad { GLfloat tx, ty, tz; @@ -218,14 +177,24 @@ struct quad }; -GLint quad_list; +/* structure for holding the pulsar data */ +typedef struct { + int screen_width, screen_height; + GLXContext *glx_context; + Window window; + XColor fg, bg; + + GLint quad_list; + float scale_x, scale_y, scale_z; + int frame; -static float scale_x=1, scale_y=1, scale_z=1; -static int frame = 0; + struct quad *quads; -struct quad *quads; +} pulsarstruct; -GLubyte * +static pulsarstruct *Pulsar = NULL; + +static GLubyte * Generate_Image(int *width, int *height, int *format) { GLubyte *result; @@ -254,18 +223,23 @@ Generate_Image(int *width, int *height, int *format) /* Create a texture in OpenGL. First an image is loaded and stored in a raster buffer, then it's */ -void Create_Texture(ModeInfo *mi, const char *filename) +static void Create_Texture(ModeInfo *mi, const char *filename) { int height, width; GLubyte *image; int format; if ( !strncmp(filename, "BUILTIN", 7)) - image = Generate_Image(&width, &height, &format); + { + BUILTIN: + image = Generate_Image(&width, &height, &format); + } else { XImage *ximage = xpm_file_to_ximage (MI_DISPLAY (mi), MI_VISUAL (mi), MI_COLORMAP (mi), filename); + if (! ximage) + goto BUILTIN; image = (GLubyte *) ximage->data; width = ximage->width; height = ximage->height; @@ -318,7 +292,8 @@ void Create_Texture(ModeInfo *mi, const char *filename) } } -void resetProjection(void) { +static void resetProjection(void) +{ glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-1, 1, -1, 1, 1, 100); @@ -327,12 +302,12 @@ void resetProjection(void) { } -void GenerateQuad(void) +static void GenerateQuad(pulsarstruct *gp) { int i; - quad_list = glGenLists(1); - glNewList(quad_list,GL_COMPILE); + gp->quad_list = glGenLists(1); + glNewList(gp->quad_list,GL_COMPILE); #if 1 glBegin(GL_QUADS); glColor4f(1,0,0,.4); glNormal3f(0,0,1); glTexCoord2f(0,0); glVertex2f(-1, -1); @@ -349,24 +324,25 @@ void GenerateQuad(void) glEnd(); glEndList(); - quads = (struct quad *) malloc(sizeof(struct quad) * num_quads); + gp->quads = (struct quad *) malloc(sizeof(struct quad) * num_quads); for (i=0; i < num_quads; i++) { - quads[i].rx = 0.; - quads[i].ry = 0.; - quads[i].rz = 0.; - quads[i].tx = 0.; - quads[i].ty = 0.; - quads[i].tz = -10; - - quads[i].drx = frand(5.0); - quads[i].dry = frand(5.0); - quads[i].drz = 0; + gp->quads[i].rx = 0.; + gp->quads[i].ry = 0.; + gp->quads[i].rz = 0.; + gp->quads[i].tx = 0.; + gp->quads[i].ty = 0.; + gp->quads[i].tz = -10; + + gp->quads[i].drx = frand(5.0); + gp->quads[i].dry = frand(5.0); + gp->quads[i].drz = 0; } } -void initializeGL(ModeInfo *mi, GLsizei width, GLsizei height) +static void initializeGL(ModeInfo *mi, GLsizei width, GLsizei height) { + pulsarstruct *gp = &Pulsar[MI_SCREEN(mi)]; GLfloat fogColor[4] = { 0.1, 0.1, 0.1, 0.1 }; glViewport( 0, 0, width, height ); @@ -392,6 +368,10 @@ void initializeGL(ModeInfo *mi, GLsizei width, GLsizei height) glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); } +# ifdef HAVE_JWZGLES /* #### glPolygonMode other than GL_FILL unimplemented */ + do_wire = 0; +# endif + if (do_wire) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else @@ -411,31 +391,34 @@ void initializeGL(ModeInfo *mi, GLsizei width, GLsizei height) if (do_texture) Create_Texture(mi, which_image); - GenerateQuad(); + GenerateQuad(gp); } -void drawQuads(void) { + +static void drawQuads(pulsarstruct *gp) +{ int i; for (i=0; i < num_quads; i++) { glPushMatrix(); - glTranslatef(quads[i].tx,0,0); - glTranslatef(0,quads[i].ty,0); - glTranslatef(0,0,quads[i].tz); - glRotatef(quads[i].rx, 1,0,0); - glRotatef(quads[i].ry, 0,1,0); - glRotatef(quads[i].rz, 0,0,1); - glCallList(quad_list); + glTranslatef(gp->quads[i].tx,0,0); + glTranslatef(0,gp->quads[i].ty,0); + glTranslatef(0,0,gp->quads[i].tz); + glRotatef(gp->quads[i].rx, 1,0,0); + glRotatef(gp->quads[i].ry, 0,1,0); + glRotatef(gp->quads[i].rz, 0,0,1); + glCallList(gp->quad_list); glPopMatrix(); - quads[i].rx += quads[i].drx; - quads[i].ry += quads[i].dry; - quads[i].rz += quads[i].drz; + gp->quads[i].rx += gp->quads[i].drx; + gp->quads[i].ry += gp->quads[i].dry; + gp->quads[i].rz += gp->quads[i].drz; } } -GLvoid drawScene(ModeInfo * mi) +static GLvoid drawScene(ModeInfo * mi) { + pulsarstruct *gp = &Pulsar[MI_SCREEN(mi)]; /* check_gl_error ("drawScene"); */ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -459,24 +442,25 @@ GLvoid drawScene(ModeInfo * mi) resetProjection(); /* use XYZ scaling factors to change the size of the pulsar */ - glScalef(scale_x, scale_y, scale_z); - drawQuads(); + glScalef(gp->scale_x, gp->scale_y, gp->scale_z); + drawQuads(gp); + mi->polygon_count = num_quads; /* update the scaling factors- cyclic */ - scale_x = cos(frame/360.)*10.; - scale_y = sin(frame/360.)*10.; - scale_z = 1; + gp->scale_x = cos(gp->frame/360.)*10.; + gp->scale_y = sin(gp->frame/360.)*10.; + gp->scale_z = 1; /* increment frame-counter */ - frame++; + gp->frame++; /* check_gl_error ("drawScene"); */ } -void draw_screensaver(ModeInfo * mi) +ENTRYPOINT void draw_pulsar(ModeInfo * mi) { - screensaverstruct *gp = &Screensaver[MI_SCREEN(mi)]; + pulsarstruct *gp = &Pulsar[MI_SCREEN(mi)]; Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); @@ -490,29 +474,29 @@ void draw_screensaver(ModeInfo * mi) } /* Standard reshape function */ -void -reshape_screensaver(ModeInfo *mi, int width, int height) +ENTRYPOINT void +reshape_pulsar(ModeInfo *mi, int width, int height) { glViewport( 0, 0, MI_WIDTH(mi), MI_HEIGHT(mi) ); resetProjection(); } -void -init_screensaver(ModeInfo * mi) +ENTRYPOINT void +init_pulsar(ModeInfo * mi) { int screen = MI_SCREEN(mi); - screensaverstruct *gp; + pulsarstruct *gp; - if (Screensaver == NULL) { - if ((Screensaver = (screensaverstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (screensaverstruct))) == NULL) - return; - } - gp = &Screensaver[screen]; + MI_INIT (mi, Pulsar); + gp = &Pulsar[screen]; gp->window = MI_WINDOW(mi); + + gp->scale_x = gp->scale_y = gp->scale_z = 1; + if ((gp->glx_context = init_GL(mi)) != NULL) { - reshape_screensaver(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); + reshape_pulsar(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); initializeGL(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } else { MI_CLEARWINDOW(mi); @@ -521,17 +505,11 @@ init_screensaver(ModeInfo * mi) /* all sorts of nice cleanup code should go here! */ -void release_screensaver(ModeInfo * mi) +ENTRYPOINT void free_pulsar(ModeInfo * mi) { - int screen; - if (Screensaver != NULL) { - for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) { -/* screensaverstruct *gp = &Screensaver[screen];*/ - } - (void) free((void *) Screensaver); - Screensaver = NULL; - } - free(quads); - FreeAllGL(mi); + pulsarstruct *gp = &Pulsar[MI_SCREEN(mi)]; + free(gp->quads); } #endif + +XSCREENSAVER_MODULE ("Pulsar", pulsar)