1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* sproingiewrap.c - sproingies wrapper */
5 static const char sccsid[] = "@(#)sproingiewrap.c 4.07 97/11/24 xlockmore";
9 * sproingiewrap.c - Copyright 1996 Sproingie Technologies Incorporated.
11 * Permission to use, copy, modify, and distribute this software and its
12 * documentation for any purpose and without fee is hereby granted,
13 * provided that the above copyright notice appear in all copies and that
14 * both that copyright notice and this permission notice appear in
15 * supporting documentation.
17 * This file is provided AS IS with no warranties of any kind. The author
18 * shall have no liability with respect to the infringement of copyrights,
19 * trade secrets or any patents by this file or any part thereof. In no
20 * event will the author be liable for any lost revenue or profits or
21 * other special, indirect and consequential damages.
23 * Programming: Ed Mackey, http://www.netaxs.com/~emackey/
24 * Gordon Wrigley, gdw33@student.canterbury.ac.nz
25 * Sproingie 3D objects modeled by: Al Mackey, al@iam.com
26 * (using MetaNURBS in NewTek's Lightwave 3D v5).
29 * 13-Dec-02: Changed triangle normals into vertex normals to give a smooth
30 apperance and moved the sproingies from Display Lists to
31 Vertex Arrays, still need to do this for the TopsSides.
33 * 26-Apr-97: Added glPointSize() calls around explosions, plus other fixes.
34 * 28-Mar-97: Added size support.
35 * 22-Mar-97: Updated to use glX interface instead of xmesa one.
36 * Also, support for multiscreens added.
37 * 20-Mar-97: Updated for xlockmore v4.02alpha7 and higher, using
38 * xlockmore's built-in Mesa/OpenGL support instead of
39 * my own. Submitted for inclusion in xlockmore.
44 * The sproingies have six "real" frames, (s1_1 to s1_6) that show a
45 * sproingie jumping off a block, headed down and to the right. But
46 * the program thinks of sproingies as having twelve "virtual" frames,
47 * with the latter six being copies of the first, only lowered and
48 * rotated by 90 degrees (jumping to the left). So after going
49 * through 12 frames, a sproingie has gone down two rows but not
52 * To have the sproingies randomly choose left/right jumps at each
53 * block, the program should go back to thinking of only 6 frames,
54 * and jumping down only one row when it is done. Then it can pick a
55 * direction for the next row.
57 * (Falling off the end might not be so bad either. :) )
61 # define DEFAULTS "*delay: 25000 \n" \
65 "*showFPS: False \n" \
67 "*wireframe: False \n"
68 # define refresh_sproingies 0
69 # define sproingies_handle_event 0
70 # include "xlockmore.h" /* from the xscreensaver distribution */
71 #else /* !STANDALONE */
72 # include "xlock.h" /* from the xlockmore distribution */
73 #endif /* !STANDALONE */
77 #include "sproingies.h"
79 ENTRYPOINT ModeSpecOpt sproingies_opts =
80 {0, NULL, 0, NULL, NULL};
83 ModStruct sproingies_description =
84 {"sproingies", "init_sproingies", "draw_sproingies", "release_sproingies",
85 "refresh_sproingies", "init_sproingies", NULL, &sproingies_opts,
86 1000, 5, 0, 400, 4, 1.0, "",
87 "Shows Sproingies! Nontoxic. Safe for pets and small children", 0, NULL};
95 void NextSproingie(int screen);
96 void NextSproingieDisplay(int screen,int pause);
97 void DisplaySproingies(int screen,int pause);
98 void ReshapeSproingies(int w, int h);
99 void CleanupSproingies(int screen);
100 void InitSproingies(int wfmode, int grnd, int mspr, int screen, int numscreens, int mono);
103 GLfloat view_rotx, view_roty, view_rotz;
104 GLint gear1, gear2, gear3;
108 GLXContext *glx_context;
113 static sproingiesstruct *sproingies = NULL;
116 init_sproingies (ModeInfo * mi)
118 Window window = MI_WINDOW(mi);
119 int screen = MI_SCREEN(mi);
121 int cycles = MI_CYCLES(mi);
122 int count = MI_COUNT(mi);
123 int size = MI_SIZE(mi);
125 sproingiesstruct *sp;
126 int wfmode = 0, grnd, mspr, w, h;
128 if (sproingies == NULL) {
129 if ((sproingies = (sproingiesstruct *) calloc(MI_NUM_SCREENS(mi),
130 sizeof (sproingiesstruct))) == NULL)
133 sp = &sproingies[screen];
135 sp->mono = (MI_IS_MONO(mi) ? 1 : 0);
137 if ((sp->glx_context = init_GL(mi)) != NULL) {
139 if ((cycles & 1) || MI_IS_WIREFRAME(mi))
141 grnd = (cycles >> 1);
149 /* wireframe, ground, maxsproingies */
150 InitSproingies(wfmode, grnd, mspr, MI_SCREEN(mi), MI_NUM_SCREENS(mi), sp->mono);
152 /* Viewport is specified size if size >= MINSIZE && size < screensize */
156 } else if (size < MINSIZE) {
160 w = (size > MI_WIDTH(mi)) ? MI_WIDTH(mi) : size;
161 h = (size > MI_HEIGHT(mi)) ? MI_HEIGHT(mi) : size;
164 glViewport((MI_WIDTH(mi) - w) / 2, (MI_HEIGHT(mi) - h) / 2, w, h);
165 glMatrixMode(GL_PROJECTION);
167 gluPerspective(65.0, (GLfloat) w / (GLfloat) h, 0.1, 2000.0); /* was 200000.0 */
168 glMatrixMode(GL_MODELVIEW);
171 DisplaySproingies(MI_SCREEN(mi),mi->pause);
180 draw_sproingies (ModeInfo * mi)
182 sproingiesstruct *sp = &sproingies[MI_SCREEN(mi)];
183 Display *display = MI_DISPLAY(mi);
184 Window window = MI_WINDOW(mi);
186 if (!sp->glx_context)
189 glDrawBuffer(GL_BACK);
190 glXMakeCurrent(display, window, *(sp->glx_context));
192 NextSproingieDisplay(MI_SCREEN(mi),mi->pause); /* It will swap. */
194 if (mi->fps_p) do_fps (mi);
196 glXSwapBuffers(MI_DISPLAY(mi), MI_WINDOW(mi));
201 refresh_sproingies(ModeInfo * mi)
203 /* No need to do anything here... The whole screen is updated
204 * every frame anyway. Otherwise this would be just like
205 * draw_sproingies, above, but replace NextSproingieDisplay(...)
206 * with DisplaySproingies(...).
209 #endif /* !STANDALONE */
212 reshape_sproingies (ModeInfo *mi, int w, int h)
214 ReshapeSproingies(w, h);
219 release_sproingies (ModeInfo * mi)
221 if (sproingies != NULL) {
224 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
225 sproingiesstruct *sp = &sproingies[screen];
227 if (sp->glx_context) {
229 glXMakeCurrent(MI_DISPLAY(mi), sp->window, *(sp->glx_context));
230 CleanupSproingies(MI_SCREEN(mi));
234 (void) free((void *) sproingies);
240 XSCREENSAVER_MODULE ("Sproingies", sproingies)
244 /* End of sproingiewrap.c */