2 static const char sccsid[] = "@(#)b_lockglue.c 4.11 98/06/16 xlockmore";
6 * BUBBLE3D (C) 1998 Richard W.M. Jones.
7 * b_lockglue.c: Glue to make this all work with xlockmore.
12 /* XXX This lot should eventually be made configurable using the
13 * options stuff below.
15 struct glb_config glb_config =
17 0, /* transparent_p */
19 2, /* subdivision_depth */
21 3, /* subdivision_depth */
23 5, /* nr_nudge_axes */
24 0.01, /* nudge_angle_factor */
25 0.20, /* nudge_factor */
26 0.1, /* rotation_factor */
27 8, /* create_bubbles_every */
29 {0.7, 0.8, 0.9, 1.0}, /* p_bubble_group */
33 0.005, /* min_speed */
34 1.5, /* scale_factor */
35 -4, /* screen_bottom */
37 {0.0, 0.0, 0.7, 0.3} /* bubble_colour */
41 # define DEFAULTS "*delay: 10000 \n" \
44 # define release_bubble3d 0
45 # define bubble3d_handle_event xlockmore_no_events
46 #include "xlockmore.h"
55 #define DEF_TRANSPARENT "True"
56 #define DEF_BUBBLECOLOR "random"
58 static Bool transparent_p;
59 static char *bubble_color_str;
62 #define countof(x) (sizeof((x))/sizeof((*x)))
64 static XrmOptionDescRec opts[] = {
65 { "-transparent", ".transparent", XrmoptionNoArg, "True" },
66 { "+transparent", ".transparent", XrmoptionNoArg, "False" },
67 { "-color", ".bubblecolor", XrmoptionSepArg, 0 },
70 static argtype vars[] = {
71 {&transparent_p, "transparent", "Transparent", DEF_TRANSPARENT, t_Bool},
72 {&bubble_color_str, "bubblecolor", "BubbleColor", DEF_BUBBLECOLOR, t_String},
75 ENTRYPOINT ModeSpecOpt bubble3d_opts = {countof(opts), opts, countof(vars), vars, NULL};
78 ModStruct bubbles3d_description =
87 1000, 1, 2, 1, 64, 1.0, "",
88 "Richard Jones's GL bubbles",
93 #endif /* USE_MODULES */
96 GLXContext *glx_context;
100 static struct context *contexts = 0;
103 parse_color (ModeInfo *mi, const char *name, const char *s, GLfloat *a)
107 if (! XParseColor (MI_DISPLAY(mi), MI_COLORMAP(mi), s, &c))
109 fprintf (stderr, "%s: can't parse %s color %s", progname, name, s);
112 a[0] = c.red / 65536.0;
113 a[1] = c.green / 65536.0;
114 a[2] = c.blue / 65536.0;
118 init_colors(ModeInfo *mi)
120 if (strncasecmp(bubble_color_str, "auto", strlen("auto")) == 0) {
121 glb_config.bubble_colour[0] = ((float) (NRAND(100)) / 100.0);
122 glb_config.bubble_colour[1] = ((float) (NRAND(100)) / 100.0);
123 /* I keep more blue */
124 glb_config.bubble_colour[2] = ((float) (NRAND(50)) / 100.0) + 0.50;
125 } else if (strncasecmp(bubble_color_str, "random", strlen("random")) == 0) {
126 glb_config.bubble_colour[0] = -1.0;
128 parse_color(mi, "bubble", bubble_color_str, glb_config.bubble_colour);
133 init(struct context *c)
135 glb_config.transparent_p = transparent_p;
137 c->draw_context = glb_draw_init();
141 reshape_bubble3d(ModeInfo *mi, int width, int height)
143 double h = (GLfloat) height / (GLfloat) width;
145 if (width > height * 5) { /* tiny window: show middle */
146 height = width * 9/16;
147 h = height / (GLfloat) width;
149 glViewport(0, 0, width, height);
150 glMatrixMode(GL_PROJECTION);
152 gluPerspective(45, 1/h, 3, 8);
153 glMatrixMode(GL_MODELVIEW);
155 glTranslatef(0, 0, -5);
159 do_display(struct context *c)
161 glb_draw_step(c->draw_context);
165 init_bubble3d(ModeInfo * mi)
167 Display *display = MI_DISPLAY(mi);
168 Window window = MI_WINDOW(mi);
169 int screen = MI_SCREEN(mi);
172 MI_INIT (mi, contexts);
173 c = &contexts[screen];
174 c->glx_context = init_GL(mi);
176 if (c->glx_context != 0) {
178 reshape_bubble3d(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
181 glXSwapBuffers(display, window);
187 draw_bubble3d(ModeInfo * mi)
189 struct context *c = &contexts[MI_SCREEN(mi)];
190 Display *display = MI_DISPLAY(mi);
191 Window window = MI_WINDOW(mi);
193 MI_IS_DRAWN(mi) = True;
198 glXMakeCurrent(display, window, *(c->glx_context));
200 glb_config.polygon_count = 0;
203 # ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */
205 GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
206 int o = (int) current_device_rotation();
207 if (o != 0 && o != 180 && o != -180)
208 glScalef (1/h, 1/h, 1/h);
209 glRotatef(o, 0, 0, 1);
215 mi->polygon_count = glb_config.polygon_count;
217 if (mi->fps_p) do_fps (mi);
219 glXSwapBuffers(display, window);
224 change_bubble3d(ModeInfo * mi)
228 #endif /* !STANDALONE */
231 free_bubble3d(ModeInfo * mi)
233 struct context *c = &contexts[MI_SCREEN(mi)];
235 glb_draw_end(c->draw_context);
238 XSCREENSAVER_MODULE ("Bubble3D", bubble3d)