X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fsproingiewrap.c;h=b8ec9c415edd3af009151f7856bbf99c033e5fae;hb=3c58fb6311db49c46f1670922933b27c6ea0c065;hp=6fb283e50ead797bd38e12c80e486519dcb6da60;hpb=f3e0240915ed9f9b3a61781f5c7002d587563fe0;p=xscreensaver diff --git a/hacks/glx/sproingiewrap.c b/hacks/glx/sproingiewrap.c index 6fb283e5..b8ec9c41 100644 --- a/hacks/glx/sproingiewrap.c +++ b/hacks/glx/sproingiewrap.c @@ -1,13 +1,13 @@ -/* -*- Mode: C; tab-width: 4 -*- - * sproingies.c --- 3D sproingies - */ +/* -*- Mode: C; tab-width: 4 -*- */ +/* sproingiewrap.c - sproingies wrapper */ + #if !defined( lint ) && !defined( SABER ) -static const char sccsid[] = "@(#)sproingiewrap.c 4.04 97/07/28 xlockmore"; +static const char sccsid[] = "@(#)sproingiewrap.c 4.07 97/11/24 xlockmore"; + #endif -/* + +/*- * sproingiewrap.c - Copyright 1996 Sproingie Technologies Incorporated. - * Source and binary freely distributable under the - * terms in xlock.c * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, @@ -21,8 +21,7 @@ static const char sccsid[] = "@(#)sproingiewrap.c 4.04 97/07/28 xlockmore"; * event will the author be liable for any lost revenue or profits or * other special, indirect and consequential damages. * - *************************************************************************** - * Programming: Ed Mackey, http://www.early.com/~emackey/ + * Programming: Ed Mackey, http://www.netaxs.com/~emackey/ * Sproingie 3D objects modeled by: Al Mackey, al@iam.com * (using MetaNURBS in NewTek's Lightwave 3D v5). * @@ -35,8 +34,6 @@ static const char sccsid[] = "@(#)sproingiewrap.c 4.04 97/07/28 xlockmore"; * xlockmore's built-in Mesa/OpenGL support instead of * my own. Submitted for inclusion in xlockmore. * 09-Dec-96: Written. - * - * Ed Mackey */ /*- @@ -60,11 +57,14 @@ static const char sccsid[] = "@(#)sproingiewrap.c 4.04 97/07/28 xlockmore"; # define PROGCLASS "Sproingies" # define HACK_INIT init_sproingies # define HACK_DRAW draw_sproingies +# define HACK_RESHAPE reshape_sproingies # define sproingies_opts xlockmore_opts -# define DEFAULTS "*count: 5 \n" \ +# define DEFAULTS "*delay: 25000 \n" \ + "*count: 5 \n" \ "*cycles: 0 \n" \ - "*delay: 100 \n" \ "*size: 0 \n" \ + "*showFPS: False \n" \ + "*fpsTop: True \n" \ "*wireframe: False \n" # include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ @@ -73,8 +73,17 @@ static const char sccsid[] = "@(#)sproingiewrap.c 4.04 97/07/28 xlockmore"; #ifdef USE_GL -ModeSpecOpt sproingies_opts = { - 0, NULL, 0, NULL, NULL }; +ModeSpecOpt sproingies_opts = +{0, NULL, 0, NULL, NULL}; + +#ifdef USE_MODULES +ModStruct sproingies_description = +{"sproingies", "init_sproingies", "draw_sproingies", "release_sproingies", + "refresh_sproingies", "init_sproingies", NULL, &sproingies_opts, + 1000, 5, 0, 400, 4, 1.0, "", + "Shows Sproingies! Nontoxic. Safe for pets and small children", 0, NULL}; + +#endif #define MINSIZE 32 @@ -82,11 +91,9 @@ ModeSpecOpt sproingies_opts = { #include void NextSproingie(int screen); -void NextSproingieDisplay(int screen); -void DisplaySproingies(int screen); -#if 0 +void NextSproingieDisplay(int screen,int pause); +void DisplaySproingies(int screen,int pause); void ReshapeSproingies(int w, int h); -#endif void CleanupSproingies(int screen); void InitSproingies(int wfmode, int grnd, int mspr, int screen, int numscreens, int mono); @@ -96,8 +103,9 @@ typedef struct { GLfloat angle; GLuint limit; GLuint count; - GLXContext glx_context; + GLXContext *glx_context; int mono; + Window window; } sproingiesstruct; static sproingiesstruct *sproingies = NULL; @@ -105,14 +113,85 @@ static sproingiesstruct *sproingies = NULL; static Display *swap_display; static Window swap_window; +static ModeInfo *global_mi_kludge; + void SproingieSwap(void) { + ModeInfo *mi = global_mi_kludge; + if (mi->fps_p) do_fps (mi); glFinish(); glXSwapBuffers(swap_display, swap_window); } +void +init_sproingies(ModeInfo * mi) +{ + Display *display = MI_DISPLAY(mi); + Window window = MI_WINDOW(mi); + int screen = MI_SCREEN(mi); + + int cycles = MI_CYCLES(mi); + int count = MI_COUNT(mi); + int size = MI_SIZE(mi); + + sproingiesstruct *sp; + int wfmode = 0, grnd, mspr, w, h; + + global_mi_kludge = mi; + + if (sproingies == NULL) { + if ((sproingies = (sproingiesstruct *) calloc(MI_NUM_SCREENS(mi), + sizeof (sproingiesstruct))) == NULL) + return; + } + sp = &sproingies[screen]; + + sp->mono = (MI_IS_MONO(mi) ? 1 : 0); + sp->window = window; + if ((sp->glx_context = init_GL(mi)) != NULL) { + + if ((cycles & 1) || MI_IS_WIREFRAME(mi)) + wfmode = 1; + grnd = (cycles >> 1); + if (grnd > 2) + grnd = 2; + + mspr = count; + if (mspr > 100) + mspr = 100; + + /* wireframe, ground, maxsproingies */ + InitSproingies(wfmode, grnd, mspr, MI_SCREEN(mi), MI_NUM_SCREENS(mi), sp->mono); + + /* Viewport is specified size if size >= MINSIZE && size < screensize */ + if (size == 0) { + w = MI_WIDTH(mi); + h = MI_HEIGHT(mi); + } else if (size < MINSIZE) { + w = MINSIZE; + h = MINSIZE; + } else { + w = (size > MI_WIDTH(mi)) ? MI_WIDTH(mi) : size; + h = (size > MI_HEIGHT(mi)) ? MI_HEIGHT(mi) : size; + } + + glViewport((MI_WIDTH(mi) - w) / 2, (MI_HEIGHT(mi) - h) / 2, w, h); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluPerspective(65.0, (GLfloat) w / (GLfloat) h, 0.1, 2000.0); /* was 200000.0 */ + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + swap_display = display; + swap_window = window; + DisplaySproingies(MI_SCREEN(mi),mi->pause); + } else { + MI_CLEARWINDOW(mi); + } +} + /* ARGSUSED */ void draw_sproingies(ModeInfo * mi) @@ -121,13 +200,16 @@ draw_sproingies(ModeInfo * mi) Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); + if (!sp->glx_context) + return; + glDrawBuffer(GL_BACK); - glXMakeCurrent(display, window, sp->glx_context); + glXMakeCurrent(display, window, *(sp->glx_context)); swap_display = display; swap_window = window; - NextSproingieDisplay(MI_SCREEN(mi)); /* It will swap. */ + NextSproingieDisplay(MI_SCREEN(mi),mi->pause); /* It will swap. */ } void @@ -140,6 +222,13 @@ refresh_sproingies(ModeInfo * mi) */ } +void +reshape_sproingies (ModeInfo *mi, int w, int h) +{ + ReshapeSproingies(w, h); +} + + void release_sproingies(ModeInfo * mi) { @@ -149,77 +238,17 @@ release_sproingies(ModeInfo * mi) for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) { sproingiesstruct *sp = &sproingies[screen]; - glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), sp->glx_context); - CleanupSproingies(MI_SCREEN(mi)); - } + if (sp->glx_context) { - /* Don't destroy the glXContext. init_GL does that. */ + glXMakeCurrent(MI_DISPLAY(mi), sp->window, *(sp->glx_context)); + CleanupSproingies(MI_SCREEN(mi)); + } + } (void) free((void *) sproingies); sproingies = NULL; } -} - -void -init_sproingies(ModeInfo * mi) -{ - Display *display = MI_DISPLAY(mi); - Window window = MI_WINDOW(mi); - int screen = MI_SCREEN(mi); - - int cycles = MI_CYCLES(mi); - int batchcount = MI_BATCHCOUNT(mi); - int size = MI_SIZE(mi); - - sproingiesstruct *sp; - int wfmode = 0, grnd, mspr, w, h; - - if (sproingies == NULL) { - if ((sproingies = (sproingiesstruct *) calloc(MI_NUM_SCREENS(mi), - sizeof (sproingiesstruct))) == NULL) - return; - } - sp = &sproingies[screen]; - - sp->mono = (MI_WIN_IS_MONO(mi) ? 1 : 0); - - sp->glx_context = init_GL(mi); - - if ((cycles & 1) || MI_WIN_IS_WIREFRAME(mi) || sp->mono) - wfmode = 1; - grnd = (cycles >> 1); - if (grnd > 2) - grnd = 2; - - mspr = batchcount; - if (mspr > 100) - mspr = 100; - - /* wireframe, ground, maxsproingies */ - InitSproingies(wfmode, grnd, mspr, MI_SCREEN(mi), MI_NUM_SCREENS(mi), sp->mono); - - /* Viewport is specified size if size >= MINSIZE && size < screensize */ - if (size == 0) { - w = MI_WIN_WIDTH(mi); - h = MI_WIN_HEIGHT(mi); - } else if (size < MINSIZE) { - w = MINSIZE; - h = MINSIZE; - } else { - w = (size > MI_WIN_WIDTH(mi)) ? MI_WIN_WIDTH(mi) : size; - h = (size > MI_WIN_HEIGHT(mi)) ? MI_WIN_HEIGHT(mi) : size; - } - - glViewport((MI_WIN_WIDTH(mi) - w) / 2, (MI_WIN_HEIGHT(mi) - h) / 2, w, h); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - gluPerspective(65.0, (GLfloat) w / (GLfloat) h, 0.1, 2000.0); /* was 200000.0 */ - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - swap_display = display; - swap_window = window; - DisplaySproingies(MI_SCREEN(mi)); + FreeAllGL(mi); } #endif