http://packetstorm.tacticalflex.com/UNIX/admin/xscreensaver-3.27.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_DRAW draw_bubble3d
53 #define bubble3d_opts xlockmore_opts
54 # define DEFAULTS ""
55 #include "xlockmore.h"
56 #else
57 #include "xlock.h"
58 #include "vis.h"
59 #endif
60
61 #ifdef USE_GL
62
63 ModeSpecOpt bubble3d_opts =
64 {0, NULL, 0, NULL, NULL};
65
66 #ifdef USE_MODULES
67 ModStruct   bubbles3d_description =
68 {"bubbles3d",
69  "init_bubble3d",
70  "draw_bubble3d",
71  "release_bubble3d",
72  "change_bubble3d",
73  "init_bubble3d",
74  NULL,
75  &bubble3d_opts,
76  1000, 1, 2, 1, 64, 1.0, "",
77  "Richard Jones's GL bubbles",
78  0,
79  NULL
80 };
81
82 #endif /* USE_MODULES */
83
84 struct context {
85         GLXContext *glx_context;
86         void       *draw_context;
87 };
88
89 static struct context *contexts = 0;
90
91 static void
92 init(struct context *c)
93 {
94         glb_sphere_init();
95         c->draw_context = glb_draw_init();
96 }
97
98 static void
99 reshape(int w, int h)
100 {
101         glViewport(0, 0, (GLsizei) w, (GLsizei) h);
102         glMatrixMode(GL_PROJECTION);
103         glLoadIdentity();
104         gluPerspective(45, (GLdouble) w / (GLdouble) h, 3, 8);
105         glMatrixMode(GL_MODELVIEW);
106         glLoadIdentity();
107         glTranslatef(0, 0, -5);
108 }
109
110 static void
111 do_display(struct context *c)
112 {
113         glb_draw_step(c->draw_context);
114 }
115
116 void
117 init_bubble3d(ModeInfo * mi)
118 {
119         Display    *display = MI_DISPLAY(mi);
120         Window      window = MI_WINDOW(mi);
121         int         screen = MI_SCREEN(mi);
122         struct context *c;
123
124         if (contexts == 0) {
125                 contexts = (struct context *) malloc(sizeof (struct context) * MI_NUM_SCREENS(mi));
126
127                 if (contexts == 0)
128                         return;
129         }
130         c = &contexts[screen];
131         c->glx_context = init_GL(mi);
132         if (c->glx_context != 0) {
133                 init(c);
134                 reshape(MI_WIDTH(mi), MI_HEIGHT(mi));
135                 do_display(c);
136                 glFinish();
137                 glXSwapBuffers(display, window);
138         } else
139                 MI_CLEARWINDOW(mi);
140 }
141
142 void
143 draw_bubble3d(ModeInfo * mi)
144 {
145         struct context *c = &contexts[MI_SCREEN(mi)];
146         Display    *display = MI_DISPLAY(mi);
147         Window      window = MI_WINDOW(mi);
148
149         MI_IS_DRAWN(mi) = True;
150
151         if (!c->glx_context)
152                 return;
153
154         glXMakeCurrent(display, window, *(c->glx_context));
155
156         do_display(c);
157
158         glFinish();
159         glXSwapBuffers(display, window);
160 }
161
162 void
163 change_bubble3d(ModeInfo * mi)
164 {
165         /* nothing */
166 }
167
168 void
169 release_bubble3d(ModeInfo * mi)
170 {
171         struct context *c = &contexts[MI_SCREEN(mi)];
172
173         if (contexts != 0) {
174                 glb_draw_end(c->draw_context);
175                 (void) free((void *) contexts);
176                 contexts = 0;
177         }
178         FreeAllGL(mi);
179 }
180
181 #endif /* USE_GL */