http://packetstormsecurity.org/UNIX/admin/xscreensaver-3.29.tar.gz
[xscreensaver] / hacks / glx / b_lockglue.c
1 #if !defined( lint ) && !defined( SABER )
2 static const char sccsid[] = "@(#)b_lockglue.c  4.11 98/06/16 xlockmore";
3
4 #endif
5
6 /*-
7  * BUBBLE3D (C) 1998 Richard W.M. Jones.
8  * b_lockglue.c: Glue to make this all work with xlockmore.
9  */
10
11 #include "bubble3d.h"
12
13 /* XXX This lot should eventually be made configurable using the
14  * options stuff below.
15  */
16 struct glb_config glb_config =
17 {
18 #if GLB_SLOW_GL
19         2,                      /* subdivision_depth */
20 #else
21         3,                      /* subdivision_depth */
22 #endif
23         5,                      /* nr_nudge_axes */
24         0.3,                    /* nudge_angle_factor */
25         0.15,                   /* nudge_factor */
26         0.1,                    /* rotation_factor */
27         8,                      /* create_bubbles_every */
28         8,                      /* max_bubbles */
29         {0.7, 0.8, 0.9, 1.0},   /* p_bubble_group */
30         0.5,                    /* max_size */
31         0.1,                    /* min_size */
32         0.1,                    /* max_speed */
33         0.03,                   /* min_speed */
34         1.5,                    /* scale_factor */
35         -4,                     /* screen_bottom */
36         4,                      /* screen_top */
37 #if 0
38         {0.1, 0.0, 0.4, 0.0},   /* bg_colour */
39 #else
40         {0.0, 0.0, 0.0, 0.0},   /* bg_colour */
41 #endif
42 #if 0
43         {0.7, 0.7, 0.0, 0.3}    /* bubble_colour */
44 #else
45         {0.0, 0.0, 0.7, 0.3}    /* bubble_colour */
46 #endif
47 };
48
49 #ifdef STANDALONE
50 #define PROGCLASS "Bubble3D"
51 #define HACK_INIT init_bubble3d
52 #define HACK_RESHAPE reshape_bubble3d
53 #define HACK_DRAW draw_bubble3d
54 #define bubble3d_opts xlockmore_opts
55
56 # define DEFAULTS       "*delay:        10000   \n"     \
57                         "*showFPS:      False   \n"
58
59 #include "xlockmore.h"
60 #else
61 #include "xlock.h"
62 #include "vis.h"
63 #endif
64
65 #ifdef USE_GL
66
67 ModeSpecOpt bubble3d_opts =
68 {0, NULL, 0, NULL, NULL};
69
70 #ifdef USE_MODULES
71 ModStruct   bubbles3d_description =
72 {"bubbles3d",
73  "init_bubble3d",
74  "draw_bubble3d",
75  "release_bubble3d",
76  "change_bubble3d",
77  "init_bubble3d",
78  NULL,
79  &bubble3d_opts,
80  1000, 1, 2, 1, 64, 1.0, "",
81  "Richard Jones's GL bubbles",
82  0,
83  NULL
84 };
85
86 #endif /* USE_MODULES */
87
88 struct context {
89         GLXContext *glx_context;
90         void       *draw_context;
91 };
92
93 static struct context *contexts = 0;
94
95 static void
96 init(struct context *c)
97 {
98         glb_sphere_init();
99         c->draw_context = glb_draw_init();
100 }
101
102 void
103 reshape_bubble3d(ModeInfo *mi, int w, int h)
104 {
105         glViewport(0, 0, (GLsizei) w, (GLsizei) h);
106         glMatrixMode(GL_PROJECTION);
107         glLoadIdentity();
108         gluPerspective(45, (GLdouble) w / (GLdouble) h, 3, 8);
109         glMatrixMode(GL_MODELVIEW);
110         glLoadIdentity();
111         glTranslatef(0, 0, -5);
112 }
113
114 static void
115 do_display(struct context *c)
116 {
117         glb_draw_step(c->draw_context);
118 }
119
120 void
121 init_bubble3d(ModeInfo * mi)
122 {
123         Display    *display = MI_DISPLAY(mi);
124         Window      window = MI_WINDOW(mi);
125         int         screen = MI_SCREEN(mi);
126         struct context *c;
127
128         if (contexts == 0) {
129                 contexts = (struct context *) malloc(sizeof (struct context) * MI_NUM_SCREENS(mi));
130
131                 if (contexts == 0)
132                         return;
133         }
134         c = &contexts[screen];
135         c->glx_context = init_GL(mi);
136         if (c->glx_context != 0) {
137                 init(c);
138                 reshape_bubble3d(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
139                 do_display(c);
140                 glFinish();
141                 glXSwapBuffers(display, window);
142         } else
143                 MI_CLEARWINDOW(mi);
144 }
145
146 void
147 draw_bubble3d(ModeInfo * mi)
148 {
149         struct context *c = &contexts[MI_SCREEN(mi)];
150         Display    *display = MI_DISPLAY(mi);
151         Window      window = MI_WINDOW(mi);
152
153         MI_IS_DRAWN(mi) = True;
154
155         if (!c->glx_context)
156                 return;
157
158         glXMakeCurrent(display, window, *(c->glx_context));
159
160         do_display(c);
161
162         if (mi->fps_p) do_fps (mi);
163         glFinish();
164         glXSwapBuffers(display, window);
165 }
166
167 void
168 change_bubble3d(ModeInfo * mi)
169 {
170         /* nothing */
171 }
172
173 void
174 release_bubble3d(ModeInfo * mi)
175 {
176         struct context *c = &contexts[MI_SCREEN(mi)];
177
178         if (contexts != 0) {
179                 glb_draw_end(c->draw_context);
180                 (void) free((void *) contexts);
181                 contexts = 0;
182         }
183         FreeAllGL(mi);
184 }
185
186 #endif /* USE_GL */