1 /* blinkbox, Copyright (c) 2003 Jeremy English <jenglish@myself.com>
3 * Permission to use, copy, modify, distribute, and sell this software and its
4 * documentation for any purpose is hereby granted without fee, provided that
5 * the above copyright notice appear in all copies and that both that
6 * copyright notice and this permission notice appear in supporting
7 * documentation. No representations are made about the suitability of this
8 * software for any purpose. It is provided "as is" without express or
12 #include <X11/Intrinsic.h>
14 extern XtAppContext app;
16 #define PROGCLASS "BlinkBox"
17 #define HACK_INIT init_ball
18 #define HACK_DRAW draw_ball
19 #define HACK_RESHAPE reshape_ball
20 #define sws_opts xlockmore_opts
24 #define DEFAULTS "*delay: 30000 \n" \
26 #include "xlockmore.h"
30 #ifdef USE_GL /* whole file */
50 } bbox = {{7,7,10},{-7,-7,-10}};
59 static GLuint ballList;
60 static GLuint boxList;
61 Tdpos mo = { 1.0, 1.0, 1.0}; /*motion*/
62 Tdpos moh= {-1.0,-1.5,-1.5}; /*hold motion value*/
64 GLfloat bscale[3] = {1,1,0.25};
68 static Side lside = {0, {0, 0, 0,}, MAX_COUNT, {1.0, 0.0, 0.0},{90,0,1,0}};/*Red*/
69 static Side rside = {0, {0, 0, 0,}, MAX_COUNT, {0.0, 1.0, 0.0},{90,0,1,0}};/*Green*/
70 static Side tside = {0, {0, 0, 0,}, MAX_COUNT, {0.0, 0.0, 1.0},{90,1,0,0}};/*Blue*/
71 static Side bside = {0, {0, 0, 0,}, MAX_COUNT, {1.0, 0.5, 0.0},{90,1,0,0}};/*Orange*/
72 static Side fside = {0, {0, 0, 0,}, MAX_COUNT, {1.0, 1.0, 0.0},{90,0,0,1}};/*Yellow*/
73 static Side aside = {0, {0, 0, 0,}, MAX_COUNT, {0.5, 0.0, 1.0},{90,0,0,1}};/*Purple*/
77 static float LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
78 static float LightPosition[]= { 20.0f, 100.0f, 20.0f, 1.0f };
80 ModeSpecOpt sws_opts = {0,NULL,0,NULL,NULL};
83 swap(GLfloat *a, GLfloat *b)
93 GLfloat j = 1+(random() % 2);
98 swap_mov(GLfloat *a, GLfloat *b)
110 cp_b_pos(Tdpos *s_pos){
119 if ((ball.x - ball.d) <= bbox.bottom.x){
121 lside.counter = MAX_COUNT;
122 cp_b_pos(&lside.pos);
123 swap_mov(&mo.x,&moh.x);
125 if ((ball.x + ball.d) >= bbox.top.x){
127 rside.counter = MAX_COUNT;
128 cp_b_pos(&rside.pos);
129 swap_mov(&mo.x,&moh.x);
136 if ((ball.y - ball.d) <= bbox.bottom.y){
138 bside.counter = MAX_COUNT;
139 cp_b_pos(&bside.pos);
140 swap_mov(&mo.y,&moh.y);
142 if ((ball.y + ball.d) >= bbox.top.y){
144 tside.counter = MAX_COUNT;
145 cp_b_pos(&tside.pos);
146 swap_mov(&mo.y,&moh.y);
153 if ((ball.z - ball.d) <= bbox.bottom.z){
155 aside.counter = MAX_COUNT;
156 cp_b_pos(&aside.pos);
157 swap_mov(&mo.z,&moh.z);
159 if((ball.z + ball.d) >= bbox.top.z){
161 fside.counter = MAX_COUNT;
162 cp_b_pos(&fside.pos);
163 swap_mov(&mo.z,&moh.z);
168 reshape_ball (ModeInfo *mi, int width, int height)
170 GLfloat h = (GLfloat) height / (GLfloat) width;
172 glViewport (0, 0, (GLint) width, (GLint) height);
173 glMatrixMode(GL_PROJECTION);
175 gluPerspective (30.0, 1/h, 1.0, 100.0);
177 glMatrixMode(GL_MODELVIEW);
179 gluLookAt( 0.0, 0.0, 40.0,
189 glNormal3f( 0.0f, -1.0f, 0.0f);
190 glVertex3f(-1.0f, -1.0f, -1.0f);
191 glVertex3f( 1.0f, -1.0f, -1.0f);
192 glVertex3f( 1.0f, -1.0f, 1.0f);
193 glVertex3f(-1.0f, -1.0f, 1.0f);
194 glNormal3f( 0.0f, 0.0f, 1.0f);
195 glVertex3f(-1.0f, -1.0f, 1.0f);
196 glVertex3f( 1.0f, -1.0f, 1.0f);
197 glVertex3f( 1.0f, 1.0f, 1.0f);
198 glVertex3f(-1.0f, 1.0f, 1.0f);
199 glNormal3f( 0.0f, 0.0f, -1.0f);
200 glVertex3f(-1.0f, -1.0f, -1.0f);
201 glVertex3f(-1.0f, 1.0f, -1.0f);
202 glVertex3f( 1.0f, 1.0f, -1.0f);
203 glVertex3f( 1.0f, -1.0f, -1.0f);
204 glNormal3f( 1.0f, 0.0f, 0.0f);
205 glVertex3f( 1.0f, -1.0f, -1.0f);
206 glVertex3f( 1.0f, 1.0f, -1.0f);
207 glVertex3f( 1.0f, 1.0f, 1.0f);
208 glVertex3f( 1.0f, -1.0f, 1.0f);
209 glNormal3f( -1.0f, 0.0f, 0.0f);
210 glVertex3f(-1.0f, -1.0f, -1.0f);
211 glVertex3f(-1.0f, -1.0f, 1.0f);
212 glVertex3f(-1.0f, 1.0f, 1.0f);
213 glVertex3f(-1.0f, 1.0f, -1.0f);
214 glNormal3f( 1.0f, 1.0f, 0.0f);
215 glVertex3f(-1.0f, 1.0f, -1.0f);
216 glVertex3f(-1.0f, 1.0f, 1.0f);
217 glVertex3f( 1.0f, 1.0f, 1.0f);
218 glVertex3f( 1.0f, 1.0f, -1.0f);
223 init_ball (ModeInfo *mi)
225 #define SPHERE_SLICES 32 /* how densely to render spheres */
226 #define SPHERE_STACKS 16
227 sp = malloc(sizeof(*sp));
229 fprintf(stderr,"Could not allocate memory\n");
233 reshape_ball(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
234 ballList = glGenLists(1);
235 glNewList(ballList, GL_COMPILE);
236 unit_sphere (SPHERE_STACKS, SPHERE_SLICES, False);
239 boxList = glGenLists(1);
240 glNewList(boxList, GL_COMPILE);
244 glEnable(GL_COLOR_MATERIAL);
245 glShadeModel(GL_SMOOTH);
246 glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
248 glEnable(GL_DEPTH_TEST);
249 glDepthFunc(GL_LEQUAL);
250 glEnable(GL_LIGHTING);
252 glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
253 glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
258 draw_ball (ModeInfo *mi)
260 Display *dpy = MI_DISPLAY(mi);
261 Window window = MI_WINDOW(mi);
264 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
270 glRotated(0.25,0,0,1);
271 glRotated(0.25,0,1,0);
272 glRotated(0.25,1,0,0);
276 glTranslatef(ball.x += mo.x,
280 glCallList(ballList);
287 bpos[0] = lside.pos.z*-1;
288 bpos[1] = lside.pos.y;
289 bpos[2] = bbox.bottom.x - bscale[3];
294 bpos[0] = rside.pos.z*-1;
295 bpos[1] = rside.pos.y;
296 bpos[2] = bbox.top.x + bscale[3];
301 bpos[0] = tside.pos.x;
302 bpos[1] = tside.pos.z;
303 bpos[2] = bbox.bottom.y - bscale[3];
308 bpos[0] = bside.pos.x;
309 bpos[1] = bside.pos.z;
310 bpos[2] = bbox.top.y + bscale[3];
315 bpos[0] = fside.pos.y;
316 bpos[1] = fside.pos.x*-1;
317 bpos[2] = bbox.top.z + bscale[3];
322 bpos[0] = aside.pos.y;
323 bpos[1] = aside.pos.x*-1;
324 bpos[2] = bbox.bottom.z + bscale[3];
329 glColor3fv(sp->color);
331 glRotatef(sp->rot[0],sp->rot[1],sp->rot[2],sp->rot[3]);
332 glTranslatef(bpos[0],bpos[1],bpos[2]);
333 /*dem = (MAX_COUNT-(sp->counter+1));*/
334 /*glScalef(bscale[0]/dem,bscale[1]/dem,bscale[2]);*/
335 glScalef(bscale[0],bscale[1],bscale[2]);
347 glXSwapBuffers(dpy, window);