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 * Sergio GutiƩrrez "Sergut", sergut@gmail.com
26 * Sproingie 3D objects modeled by: Al Mackey, al@iam.com
27 * (using MetaNURBS in NewTek's Lightwave 3D v5).
30 * 01-Sep-06: Make the sproingies select a new direction after each hop
31 * (6 frames); if they fall towards the edge, they explode.
32 * (TODO: let them fall for a time before they explode or
34 * 13-Dec-02: Changed triangle normals into vertex normals to give a smooth
35 * apperance and moved the sproingies from Display Lists to
36 * Vertex Arrays, still need to do this for the TopsSides.
38 * 26-Apr-97: Added glPointSize() calls around explosions, plus other fixes.
39 * 28-Mar-97: Added size support.
40 * 22-Mar-97: Updated to use glX interface instead of xmesa one.
41 * Also, support for multiscreens added.
42 * 20-Mar-97: Updated for xlockmore v4.02alpha7 and higher, using
43 * xlockmore's built-in Mesa/OpenGL support instead of
44 * my own. Submitted for inclusion in xlockmore.
49 # define DEFAULTS "*delay: 30000 \n" \
52 "*showFPS: False \n" \
54 "*wireframe: False \n"
56 # define release_sproingies 0
57 # define sproingies_handle_event 0
58 # include "xlockmore.h" /* from the xscreensaver distribution */
59 #else /* !STANDALONE */
60 # include "xlock.h" /* from the xlockmore distribution */
61 #endif /* !STANDALONE */
65 #define DEF_SMART_SPROINGIES "True" /* Smart sproingies do not fall down the edge */
67 #include "sproingies.h"
70 #define countof(x) (sizeof((x))/sizeof((*x)))
72 static XrmOptionDescRec opts[] = {
73 {"-fall", ".smartSproingies", XrmoptionNoArg, "False"},
74 {"-no-fall", ".smartSproingies", XrmoptionNoArg, "True"},
79 static argtype vars[] = {
80 {&smrt_spr, "smartSproingies", "Boolean", DEF_SMART_SPROINGIES, t_Bool},
83 ENTRYPOINT ModeSpecOpt sproingies_opts =
84 {countof(opts), opts, countof(vars), vars, NULL};
87 ModStruct sproingies_description =
88 {"sproingies", "init_sproingies", "draw_sproingies", NULL,
89 "refresh_sproingies", "init_sproingies", "free_sproingies", &sproingies_opts,
90 1000, 5, 0, 400, 4, 1.0, "",
91 "Shows Sproingies! Nontoxic. Safe for pets and small children", 0, NULL};
100 GLfloat view_rotx, view_roty, view_rotz;
101 GLint gear1, gear2, gear3;
105 GLXContext *glx_context;
111 static sproingiesstruct *sproingies = NULL;
115 init_sproingies (ModeInfo * mi)
117 Window window = MI_WINDOW(mi);
118 int screen = MI_SCREEN(mi);
120 int count = MI_COUNT(mi);
121 int size = MI_SIZE(mi);
123 sproingiesstruct *sp;
124 int wfmode = 0, grnd = 0, mspr, w, h;
126 MI_INIT (mi, sproingies);
127 sp = &sproingies[screen];
129 sp->mono = (MI_IS_MONO(mi) ? 1 : 0);
131 if ((sp->glx_context = init_GL(mi)) != NULL) {
133 if (MI_IS_WIREFRAME(mi))
143 /* wireframe, ground, maxsproingies */
144 InitSproingies(&sp->si, wfmode, grnd, mspr, smrt_spr, sp->mono);
146 /* Viewport is specified size if size >= MINSIZE && size < screensize */
150 } else if (size < MINSIZE) {
154 w = (size > MI_WIDTH(mi)) ? MI_WIDTH(mi) : size;
155 h = (size > MI_HEIGHT(mi)) ? MI_HEIGHT(mi) : size;
158 glViewport((MI_WIDTH(mi) - w) / 2, (MI_HEIGHT(mi) - h) / 2, w, h);
159 glMatrixMode(GL_PROJECTION);
161 gluPerspective(65.0, (GLfloat) w / (GLfloat) h, 0.1, 2000.0); /* was 200000.0 */
162 glMatrixMode(GL_MODELVIEW);
165 DisplaySproingies(&sp->si);
174 draw_sproingies (ModeInfo * mi)
176 sproingiesstruct *sp = &sproingies[MI_SCREEN(mi)];
177 Display *display = MI_DISPLAY(mi);
178 Window window = MI_WINDOW(mi);
180 if (!sp->glx_context)
183 glDrawBuffer(GL_BACK);
184 glXMakeCurrent(display, window, *(sp->glx_context));
187 glRotatef(current_device_rotation(), 0, 0, 1);
188 NextSproingieDisplay(&sp->si); /* It will swap. */
191 if (mi->fps_p) do_fps (mi);
193 glXSwapBuffers(MI_DISPLAY(mi), MI_WINDOW(mi));
198 refresh_sproingies(ModeInfo * mi)
200 /* No need to do anything here... The whole screen is updated
201 * every frame anyway. Otherwise this would be just like
202 * draw_sproingies, above, but replace NextSproingieDisplay(...)
203 * with DisplaySproingies(...).
206 #endif /* !STANDALONE */
209 reshape_sproingies (ModeInfo *mi, int w, int h)
211 ReshapeSproingies(w, h);
216 free_sproingies (ModeInfo * mi)
218 sproingiesstruct *sp = &sproingies[MI_SCREEN(mi)];
220 if (sp->glx_context) {
222 glXMakeCurrent(MI_DISPLAY(mi), sp->window, *(sp->glx_context));
223 CleanupSproingies(&sp->si);
227 XSCREENSAVER_MODULE ("Sproingies", sproingies)
231 /* End of sproingiewrap.c */