2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the name of
8 * Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Silicon Graphics.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
26 * Nov 20, 1995 use stdlib's rand()/srand() instead of random()/srand48(), etc.
30 * Modified by Stephane Raimbault to be able to run in VxWorks 07/18/01
32 * Modified by Li Wei(liwei@aiar.xjtu.edu.cn) to be able to run in Windows
35 * Modified by Brian Paul to compile with Windows OR Unix. 7/23/97
45 #include <ugl/uglevent.h>
46 #include <ugl/uglinput.h>
47 #include <ugl/uglucode.h>
49 #include <GL/uglmesa.h>
53 # define RAND_MAX 32767
68 UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId
;
69 UGL_LOCAL UGL_EVENT_Q_ID qId
;
70 UGL_LOCAL UGL_MESA_CONTEXT umc
;
71 UGL_LOCAL
volatile UGL_BOOL stopWex
;
74 UGL_LOCAL
unsigned char rgb_colors
[RINGS
][3];
75 UGL_LOCAL
int mapped_colors
[RINGS
];
76 UGL_LOCAL
float dests
[RINGS
][3];
77 UGL_LOCAL
float offsets
[RINGS
][3];
78 UGL_LOCAL
float angs
[RINGS
];
79 UGL_LOCAL
float rotAxis
[RINGS
][3];
80 UGL_LOCAL
int iters
[RINGS
];
81 UGL_LOCAL GLuint theTorus
;
95 UGL_LOCAL float RGBMap[9][3] = {
107 UGL_LOCAL void SetColor(int c)
109 (rgb) ? glColor3fv(RGBMap[c]): glIndexf(c);
112 UGL_LOCAL void InitMap(void)
119 for (i = 0; i < 9; i++)
120 uglMesaSetColor(i, RGBMap[i][0], RGBMap[i][1], RGBMap[i][2]);
123 UGL_LOCAL void SetFogRamp(int density, int startIndex)
125 int fogValues, colorValues;
129 fogValues = 1 << density;
130 colorValues = 1 << startIndex;
131 for (i = 0; i < colorValues; i++)
133 for (j = 0; j < fogValues; j++)
135 k = i * fogValues + j;
136 intensity = (i * fogValues + j * colorValues) / 255.0;
137 uglMesaSetColor(k, intensity, intensity, intensity);
142 UGL_LOCAL void SetGreyRamp(void)
147 for (i = 0; i < 255; i++)
149 intensity = i / 255.0;
150 uglMesaSetColor(i, intensity, intensity, intensity);
155 UGL_LOCAL
void FillTorus(float rc
, int numc
, float rt
, int numt
)
162 pi
= 3.14159265358979323846;
165 for (i
= 0; i
< numc
; i
++)
167 glBegin(GL_QUAD_STRIP
);
168 for (j
= 0; j
<= numt
; j
++)
170 for (k
= 1; k
>= 0; k
--)
172 s
= (i
+ k
) % numc
+ 0.5;
175 x
= cos(t
*twopi
/numt
) * cos(s
*twopi
/numc
);
176 y
= sin(t
*twopi
/numt
) * cos(s
*twopi
/numc
);
177 z
= sin(s
*twopi
/numc
);
180 x
= (rt
+ rc
* cos(s
*twopi
/numc
)) * cos(t
*twopi
/numt
);
181 y
= (rt
+ rc
* cos(s
*twopi
/numc
)) * sin(t
*twopi
/numt
);
182 z
= rc
* sin(s
*twopi
/numc
);
190 UGL_LOCAL
float Clamp(int iters_left
, float t
)
196 return (iters_left
-2)*t
/iters_left
;
199 UGL_LOCAL
void drawGL(void)
203 for (i
= 0; i
< RINGS
; i
++)
206 for (j
= 0; j
< 3; j
++)
208 offsets
[i
][j
] = Clamp(iters
[i
], offsets
[i
][j
]);
210 angs
[i
] = Clamp(iters
[i
], angs
[i
]);
217 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
218 gluLookAt(0,0,10, 0,0,0, 0,1,0);
220 for (i
= 0; i
< RINGS
; i
++)
224 glColor3ubv(rgb_colors
[i
]);
228 glIndexi(mapped_colors
[i
]);
231 glTranslatef(dests
[i
][0]+offsets
[i
][0], dests
[i
][1]+offsets
[i
][1],
232 dests
[i
][2]+offsets
[i
][2]);
233 glRotatef(angs
[i
], rotAxis
[i
][0], rotAxis
[i
][1], rotAxis
[i
][2]);
234 glCallList(theTorus
);
242 uglMesaSwapBuffers();
245 UGL_LOCAL
float MyRand(void)
247 return 10.0 * ( (float) rand() / (float) RAND_MAX
- 0.5 );
250 UGL_LOCAL
void ReInit(void)
255 deviation
= MyRand() / 2;
256 deviation
= deviation
* deviation
;
257 for (i
= 0; i
< RINGS
; i
++)
259 offsets
[i
][0] = MyRand();
260 offsets
[i
][1] = MyRand();
261 offsets
[i
][2] = MyRand();
262 angs
[i
] = 260.0 * MyRand();
263 rotAxis
[i
][0] = MyRand();
264 rotAxis
[i
][1] = MyRand();
265 rotAxis
[i
][2] = MyRand();
266 iters
[i
] = (deviation
* MyRand() + 60.0);
270 UGL_LOCAL
void initGL(void)
277 float bottom_y
= 0.0;
279 float bottom_z
= 0.69;
281 static float lmodel_ambient
[] = {0.0, 0.0, 0.0, 0.0};
282 static float lmodel_twoside
[] = {GL_FALSE
};
283 static float lmodel_local
[] = {GL_FALSE
};
284 static float light0_ambient
[] = {0.1, 0.1, 0.1, 1.0};
285 static float light0_diffuse
[] = {1.0, 1.0, 1.0, 0.0};
286 static float light0_position
[] = {0.8660254, 0.5, 1, 0};
287 static float light0_specular
[] = {1.0, 1.0, 1.0, 0.0};
288 static float bevel_mat_ambient
[] = {0.0, 0.0, 0.0, 1.0};
289 static float bevel_mat_shininess
[] = {40.0};
290 static float bevel_mat_specular
[] = {1.0, 1.0, 1.0, 0.0};
291 static float bevel_mat_diffuse
[] = {1.0, 0.0, 0.0, 0.0};
295 for (i
= 0; i
< RINGS
; i
++)
297 rgb_colors
[i
][0] = rgb_colors
[i
][1] = rgb_colors
[i
][2] = 0;
299 rgb_colors
[BLUERING
][2] = 255;
300 rgb_colors
[REDRING
][0] = 255;
301 rgb_colors
[GREENRING
][1] = 255;
302 rgb_colors
[YELLOWRING
][0] = 255;
303 rgb_colors
[YELLOWRING
][1] = 255;
304 mapped_colors
[BLUERING
] = COLOR_BLUE
;
305 mapped_colors
[REDRING
] = COLOR_RED
;
306 mapped_colors
[GREENRING
] = COLOR_GREEN
;
307 mapped_colors
[YELLOWRING
] = COLOR_YELLOW
;
308 mapped_colors
[BLACKRING
] = COLOR_BLACK
;
310 dests
[BLUERING
][0] = -spacing
;
311 dests
[BLUERING
][1] = top_y
;
312 dests
[BLUERING
][2] = top_z
;
314 dests
[BLACKRING
][0] = 0.0;
315 dests
[BLACKRING
][1] = top_y
;
316 dests
[BLACKRING
][2] = top_z
;
318 dests
[REDRING
][0] = spacing
;
319 dests
[REDRING
][1] = top_y
;
320 dests
[REDRING
][2] = top_z
;
322 dests
[YELLOWRING
][0] = -spacing
/ 2.0;
323 dests
[YELLOWRING
][1] = bottom_y
;
324 dests
[YELLOWRING
][2] = bottom_z
;
326 dests
[GREENRING
][0] = spacing
/ 2.0;
327 dests
[GREENRING
][1] = bottom_y
;
328 dests
[GREENRING
][2] = bottom_z
;
332 theTorus
= glGenLists(1);
333 glNewList(theTorus
, GL_COMPILE
);
334 FillTorus(0.1, 8, 1.0, 25);
340 glEnable(GL_CULL_FACE
);
342 glEnable(GL_DEPTH_TEST
);
347 glClearColor(0.5, 0.5, 0.5, 0.0);
348 glLightfv(GL_LIGHT0
, GL_AMBIENT
, light0_ambient
);
349 glLightfv(GL_LIGHT0
, GL_DIFFUSE
, light0_diffuse
);
350 glLightfv(GL_LIGHT0
, GL_SPECULAR
, light0_specular
);
351 glLightfv(GL_LIGHT0
, GL_POSITION
, light0_position
);
354 glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER
, lmodel_local
);
355 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE
, lmodel_twoside
);
356 glLightModelfv(GL_LIGHT_MODEL_AMBIENT
, lmodel_ambient
);
357 glEnable(GL_LIGHTING
);
359 glMaterialfv(GL_FRONT
, GL_AMBIENT
, bevel_mat_ambient
);
360 glMaterialfv(GL_FRONT
, GL_SHININESS
, bevel_mat_shininess
);
361 glMaterialfv(GL_FRONT
, GL_SPECULAR
, bevel_mat_specular
);
362 glMaterialfv(GL_FRONT
, GL_DIFFUSE
, bevel_mat_diffuse
);
364 glColorMaterial(GL_FRONT_AND_BACK
, GL_DIFFUSE
);
365 glEnable(GL_COLOR_MATERIAL
);
366 glShadeModel(GL_SMOOTH
);
370 glClearIndex(BACKGROUND
);
371 glShadeModel(GL_FLAT
);
374 glMatrixMode(GL_PROJECTION
);
375 gluPerspective(45, 1.33, 0.1, 100.0);
376 glMatrixMode(GL_MODELVIEW
);
379 UGL_LOCAL
void echoUse(void)
381 printf("tOlympic keys:\n");
382 printf(" SPACE Reinitialize\n");
383 printf(" ESC Exit\n");
386 UGL_LOCAL
void readKey (UGL_WCHAR key
)
399 UGL_LOCAL
void loopEvent(void)
402 UGL_INPUT_EVENT
* pInputEvent
;
406 if (uglEventGet (qId
, &event
, sizeof (event
), UGL_NO_WAIT
)
407 != UGL_STATUS_Q_EMPTY
)
409 pInputEvent
= (UGL_INPUT_EVENT
*)&event
;
411 if (pInputEvent
->header
.type
== UGL_EVENT_TYPE_KEYBOARD
&&
412 pInputEvent
->modifiers
& UGL_KEYBOARD_KEYDOWN
)
413 readKey(pInputEvent
->type
.keyboard
.key
);
422 void windMLOlympic (UGL_BOOL windMLMode
);
424 void uglolympic (void)
426 taskSpawn("tOlympic", 210, VX_FP_TASK
, 100000, (FUNCPTR
)windMLOlympic
,
427 0,1,2,3,4,5,6,7,8,9);
430 void windMLOlympic(UGL_BOOL windMLMode
)
432 UGL_INPUT_DEVICE_ID keyboardDevId
;
436 uglDriverFind (UGL_KEYBOARD_TYPE
, 0, (UGL_UINT32
*)&keyboardDevId
);
438 if (uglDriverFind (UGL_EVENT_SERVICE_TYPE
, 0,
439 (UGL_UINT32
*)&eventServiceId
) == UGL_STATUS_OK
)
441 qId
= uglEventQCreate (eventServiceId
, 100);
445 eventServiceId
= UGL_NULL
;
449 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
450 | UGL_MESA_WINDML_EXCLUSIVE
, NULL
);
452 umc
= uglMesaCreateNewContext(UGL_MESA_DOUBLE
, NULL
);
460 uglMesaMakeCurrentContext(umc
, 0, 0, UGL_MESA_FULLSCREEN_WIDTH
,
461 UGL_MESA_FULLSCREEN_HEIGHT
);
463 uglMesaGetIntegerv(UGL_MESA_RGB
, &rgb
);
472 if (eventServiceId
!= UGL_NULL
)
473 uglEventQDestroy (eventServiceId
, qId
);
475 uglMesaDestroyContext();