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 */
38 {0.1, 0.0, 0.4, 0.0}, /* bg_colour */
40 {0.0, 0.0, 0.0, 0.0}, /* bg_colour */
43 {0.7, 0.7, 0.0, 0.3} /* bubble_colour */
45 {0.0, 0.0, 0.7, 0.3} /* bubble_colour */
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
56 # define DEFAULTS "*delay: 10000 \n" \
59 #define DEF_TRANSPARENT "False"
60 #define DEF_COLOR "random"
62 #include "xlockmore.h"
70 static Bool transparent_p;
71 static char *bubble_color_str;
74 #define countof(x) (sizeof((x))/sizeof((*x)))
76 static XrmOptionDescRec opts[] = {
77 { "-transparent", ".transparent", XrmoptionNoArg, "True" },
78 { "+transparent", ".transparent", XrmoptionNoArg, "False" },
79 { "-color", ".bubble3d.bubblecolor", XrmoptionSepArg, 0 },
82 static argtype vars[] = {
83 {&transparent_p, "transparent", "Transparent", DEF_TRANSPARENT, t_Bool},
84 {&bubble_color_str, "bubblecolor", "BubbleColor", DEF_COLOR, t_String},
87 ModeSpecOpt bubble3d_opts = {countof(opts), opts, countof(vars), vars, NULL};
90 ModStruct bubbles3d_description =
99 1000, 1, 2, 1, 64, 1.0, "",
100 "Richard Jones's GL bubbles",
105 #endif /* USE_MODULES */
108 GLXContext *glx_context;
112 static struct context *contexts = 0;
115 parse_color (ModeInfo *mi, const char *name, const char *s, GLfloat *a)
119 if (! XParseColor (MI_DISPLAY(mi), MI_COLORMAP(mi), s, &c))
121 fprintf (stderr, "%s: can't parse %s color %s", progname, name, s);
124 a[0] = c.red / 65536.0;
125 a[1] = c.green / 65536.0;
126 a[2] = c.blue / 65536.0;
130 init_colors(ModeInfo *mi)
132 if (strncasecmp(bubble_color_str, "auto", strlen("auto")) == 0) {
133 glb_config.bubble_colour[0] = ((float) (NRAND(100)) / 100.0);
134 glb_config.bubble_colour[1] = ((float) (NRAND(100)) / 100.0);
135 /* I keep more blue */
136 glb_config.bubble_colour[2] = ((float) (NRAND(50)) / 100.0) + 0.50;
137 } else if (strncasecmp(bubble_color_str, "random", strlen("random")) == 0) {
138 glb_config.bubble_colour[0] = -1.0;
140 parse_color(mi, "bubble", bubble_color_str, glb_config.bubble_colour);
145 init(struct context *c)
147 glb_config.transparent_p = transparent_p;
149 c->draw_context = glb_draw_init();
153 reshape_bubble3d(ModeInfo *mi, int w, int h)
155 glViewport(0, 0, (GLsizei) w, (GLsizei) h);
156 glMatrixMode(GL_PROJECTION);
158 gluPerspective(45, (GLdouble) w / (GLdouble) h, 3, 8);
159 glMatrixMode(GL_MODELVIEW);
161 glTranslatef(0, 0, -5);
165 do_display(struct context *c)
167 glb_draw_step(c->draw_context);
171 init_bubble3d(ModeInfo * mi)
173 Display *display = MI_DISPLAY(mi);
174 Window window = MI_WINDOW(mi);
175 int screen = MI_SCREEN(mi);
179 contexts = (struct context *) malloc(sizeof (struct context) * MI_NUM_SCREENS(mi));
184 c = &contexts[screen];
185 c->glx_context = init_GL(mi);
187 if (c->glx_context != 0) {
189 reshape_bubble3d(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
192 glXSwapBuffers(display, window);
198 draw_bubble3d(ModeInfo * mi)
200 struct context *c = &contexts[MI_SCREEN(mi)];
201 Display *display = MI_DISPLAY(mi);
202 Window window = MI_WINDOW(mi);
204 MI_IS_DRAWN(mi) = True;
209 glXMakeCurrent(display, window, *(c->glx_context));
211 glb_config.polygon_count = 0;
213 mi->polygon_count = glb_config.polygon_count;
215 if (mi->fps_p) do_fps (mi);
217 glXSwapBuffers(display, window);
221 change_bubble3d(ModeInfo * mi)
227 release_bubble3d(ModeInfo * mi)
229 struct context *c = &contexts[MI_SCREEN(mi)];
232 glb_draw_end(c->draw_context);
233 (void) free((void *) contexts);