1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* sproingiewrap.c - sproingies wrapper */
4 #if !defined( lint ) && !defined( SABER )
5 static const char sccsid[] = "@(#)sproingiewrap.c 4.07 97/11/24 xlockmore";
10 * sproingiewrap.c - Copyright 1996 Sproingie Technologies Incorporated.
12 * Permission to use, copy, modify, and distribute this software and its
13 * documentation for any purpose and without fee is hereby granted,
14 * provided that the above copyright notice appear in all copies and that
15 * both that copyright notice and this permission notice appear in
16 * supporting documentation.
18 * This file is provided AS IS with no warranties of any kind. The author
19 * shall have no liability with respect to the infringement of copyrights,
20 * trade secrets or any patents by this file or any part thereof. In no
21 * event will the author be liable for any lost revenue or profits or
22 * other special, indirect and consequential damages.
24 * Programming: Ed Mackey, http://www.netaxs.com/~emackey/
25 * Sproingie 3D objects modeled by: Al Mackey, al@iam.com
26 * (using MetaNURBS in NewTek's Lightwave 3D v5).
29 * 26-Apr-97: Added glPointSize() calls around explosions, plus other fixes.
30 * 28-Mar-97: Added size support.
31 * 22-Mar-97: Updated to use glX interface instead of xmesa one.
32 * Also, support for multiscreens added.
33 * 20-Mar-97: Updated for xlockmore v4.02alpha7 and higher, using
34 * xlockmore's built-in Mesa/OpenGL support instead of
35 * my own. Submitted for inclusion in xlockmore.
40 * The sproingies have six "real" frames, (s1_1 to s1_6) that show a
41 * sproingie jumping off a block, headed down and to the right. But
42 * the program thinks of sproingies as having twelve "virtual" frames,
43 * with the latter six being copies of the first, only lowered and
44 * rotated by 90 degrees (jumping to the left). So after going
45 * through 12 frames, a sproingie has gone down two rows but not
48 * To have the sproingies randomly choose left/right jumps at each
49 * block, the program should go back to thinking of only 6 frames,
50 * and jumping down only one row when it is done. Then it can pick a
51 * direction for the next row.
53 * (Falling off the end might not be so bad either. :) )
57 # define PROGCLASS "Sproingies"
58 # define HACK_INIT init_sproingies
59 # define HACK_DRAW draw_sproingies
60 # define sproingies_opts xlockmore_opts
61 # define DEFAULTS "*delay: 20000 \n" \
65 "*wireframe: False \n"
66 # include "xlockmore.h" /* from the xscreensaver distribution */
67 #else /* !STANDALONE */
68 # include "xlock.h" /* from the xlockmore distribution */
69 #endif /* !STANDALONE */
73 ModeSpecOpt sproingies_opts =
74 {0, NULL, 0, NULL, NULL};
77 ModStruct sproingies_description =
78 {"sproingies", "init_sproingies", "draw_sproingies", "release_sproingies",
79 "refresh_sproingies", "init_sproingies", NULL, &sproingies_opts,
80 1000, 5, 0, 400, 4, 1.0, "",
81 "Shows Sproingies! Nontoxic. Safe for pets and small children", 0, NULL};
90 void NextSproingie(int screen);
91 void NextSproingieDisplay(int screen,int pause);
92 void DisplaySproingies(int screen,int pause);
95 void ReshapeSproingies(int w, int h);
98 void CleanupSproingies(int screen);
99 void InitSproingies(int wfmode, int grnd, int mspr, int screen, int numscreens, int mono);
102 GLfloat view_rotx, view_roty, view_rotz;
103 GLint gear1, gear2, gear3;
107 GLXContext *glx_context;
112 static sproingiesstruct *sproingies = NULL;
114 static Display *swap_display;
115 static Window swap_window;
121 glXSwapBuffers(swap_display, swap_window);
126 init_sproingies(ModeInfo * mi)
128 Display *display = MI_DISPLAY(mi);
129 Window window = MI_WINDOW(mi);
130 int screen = MI_SCREEN(mi);
132 int cycles = MI_CYCLES(mi);
133 int count = MI_COUNT(mi);
134 int size = MI_SIZE(mi);
136 sproingiesstruct *sp;
137 int wfmode = 0, grnd, mspr, w, h;
139 if (sproingies == NULL) {
140 if ((sproingies = (sproingiesstruct *) calloc(MI_NUM_SCREENS(mi),
141 sizeof (sproingiesstruct))) == NULL)
144 sp = &sproingies[screen];
146 sp->mono = (MI_IS_MONO(mi) ? 1 : 0);
148 if ((sp->glx_context = init_GL(mi)) != NULL) {
150 if ((cycles & 1) || MI_IS_WIREFRAME(mi))
152 grnd = (cycles >> 1);
160 /* wireframe, ground, maxsproingies */
161 InitSproingies(wfmode, grnd, mspr, MI_SCREEN(mi), MI_NUM_SCREENS(mi), sp->mono);
163 /* Viewport is specified size if size >= MINSIZE && size < screensize */
167 } else if (size < MINSIZE) {
171 w = (size > MI_WIDTH(mi)) ? MI_WIDTH(mi) : size;
172 h = (size > MI_HEIGHT(mi)) ? MI_HEIGHT(mi) : size;
175 glViewport((MI_WIDTH(mi) - w) / 2, (MI_HEIGHT(mi) - h) / 2, w, h);
176 glMatrixMode(GL_PROJECTION);
178 gluPerspective(65.0, (GLfloat) w / (GLfloat) h, 0.1, 2000.0); /* was 200000.0 */
179 glMatrixMode(GL_MODELVIEW);
182 swap_display = display;
183 swap_window = window;
184 DisplaySproingies(MI_SCREEN(mi),mi->pause);
192 draw_sproingies(ModeInfo * mi)
194 sproingiesstruct *sp = &sproingies[MI_SCREEN(mi)];
195 Display *display = MI_DISPLAY(mi);
196 Window window = MI_WINDOW(mi);
198 if (!sp->glx_context)
201 glDrawBuffer(GL_BACK);
202 glXMakeCurrent(display, window, *(sp->glx_context));
204 swap_display = display;
205 swap_window = window;
207 NextSproingieDisplay(MI_SCREEN(mi),mi->pause); /* It will swap. */
211 refresh_sproingies(ModeInfo * mi)
213 /* No need to do anything here... The whole screen is updated
214 * every frame anyway. Otherwise this would be just like
215 * draw_sproingies, above, but replace NextSproingieDisplay(...)
216 * with DisplaySproingies(...).
221 release_sproingies(ModeInfo * mi)
223 if (sproingies != NULL) {
226 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
227 sproingiesstruct *sp = &sproingies[screen];
229 if (sp->glx_context) {
231 glXMakeCurrent(MI_DISPLAY(mi), sp->window, *(sp->glx_context));
232 CleanupSproingies(MI_SCREEN(mi));
236 (void) free((void *) sproingies);
244 /* End of sproingiewrap.c */