Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. /*
  2. * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
  3. *
  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.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
  13. * ANY KIND,
  14. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  15. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  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
  22. * OF THIS SOFTWARE.
  23. */
  24. /*
  25. * Nov 20, 1995 use stdlib's rand()/srand() instead of random()/srand48(), etc.
  26. */
  27. /*
  28. * Modified by Stephane Raimbault to be able to run in VxWorks 07/18/01
  29. *
  30. * Modified by Li Wei(liwei@aiar.xjtu.edu.cn) to be able to run in Windows
  31. * 6/13
  32. *
  33. * Modified by Brian Paul to compile with Windows OR Unix. 7/23/97
  34. */
  35. #include <stdio.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <math.h>
  39. #include <ugl/ugl.h>
  40. #include <ugl/uglevent.h>
  41. #include <ugl/uglinput.h>
  42. #include <ugl/uglucode.h>
  43. #include <GL/uglmesa.h>
  44. #include <GL/glu.h>
  45. #ifndef RAND_MAX
  46. # define RAND_MAX 32767
  47. #endif
  48. #define XSIZE 100
  49. #define YSIZE 75
  50. #define RINGS 5
  51. #define BLUERING 0
  52. #define BLACKRING 1
  53. #define REDRING 2
  54. #define YELLOWRING 3
  55. #define GREENRING 4
  56. #define BACKGROUND 8
  57. UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId;
  58. UGL_LOCAL UGL_EVENT_Q_ID qId;
  59. UGL_LOCAL UGL_MESA_CONTEXT umc;
  60. UGL_LOCAL volatile UGL_BOOL stopWex;
  61. UGL_LOCAL int rgb;
  62. UGL_LOCAL unsigned char rgb_colors[RINGS][3];
  63. UGL_LOCAL int mapped_colors[RINGS];
  64. UGL_LOCAL float dests[RINGS][3];
  65. UGL_LOCAL float offsets[RINGS][3];
  66. UGL_LOCAL float angs[RINGS];
  67. UGL_LOCAL float rotAxis[RINGS][3];
  68. UGL_LOCAL int iters[RINGS];
  69. UGL_LOCAL GLuint theTorus;
  70. enum {
  71. COLOR_BLACK = 0,
  72. COLOR_RED,
  73. COLOR_GREEN,
  74. COLOR_YELLOW,
  75. COLOR_BLUE,
  76. COLOR_MAGENTA,
  77. COLOR_CYAN,
  78. COLOR_WHITE
  79. };
  80. /*
  81. UGL_LOCAL float RGBMap[9][3] = {
  82. {0, 0, 0},
  83. {1, 0, 0},
  84. {0, 1, 0},
  85. {1, 1, 0},
  86. {0, 0, 1},
  87. {1, 0, 1},
  88. {0, 1, 1},
  89. {1, 1, 1},
  90. {0.5, 0.5, 0.5}
  91. };
  92. UGL_LOCAL void SetColor(int c)
  93. {
  94. (rgb) ? glColor3fv(RGBMap[c]): glIndexf(c);
  95. }
  96. UGL_LOCAL void InitMap(void)
  97. {
  98. int i;
  99. if (rgb)
  100. return;
  101. for (i = 0; i < 9; i++)
  102. uglMesaSetColor(i, RGBMap[i][0], RGBMap[i][1], RGBMap[i][2]);
  103. }
  104. UGL_LOCAL void SetFogRamp(int density, int startIndex)
  105. {
  106. int fogValues, colorValues;
  107. int i, j, k;
  108. float intensity;
  109. fogValues = 1 << density;
  110. colorValues = 1 << startIndex;
  111. for (i = 0; i < colorValues; i++)
  112. {
  113. for (j = 0; j < fogValues; j++)
  114. {
  115. k = i * fogValues + j;
  116. intensity = (i * fogValues + j * colorValues) / 255.0;
  117. uglMesaSetColor(k, intensity, intensity, intensity);
  118. }
  119. }
  120. }
  121. UGL_LOCAL void SetGreyRamp(void)
  122. {
  123. int i;
  124. float intensity;
  125. for (i = 0; i < 255; i++)
  126. {
  127. intensity = i / 255.0;
  128. uglMesaSetColor(i, intensity, intensity, intensity);
  129. }
  130. }
  131. */
  132. UGL_LOCAL void FillTorus(float rc, int numc, float rt, int numt)
  133. {
  134. int i, j, k;
  135. double s, t;
  136. double x, y, z;
  137. double pi, twopi;
  138. pi = 3.14159265358979323846;
  139. twopi = 2 * pi;
  140. for (i = 0; i < numc; i++)
  141. {
  142. glBegin(GL_QUAD_STRIP);
  143. for (j = 0; j <= numt; j++)
  144. {
  145. for (k = 1; k >= 0; k--)
  146. {
  147. s = (i + k) % numc + 0.5;
  148. t = j % numt;
  149. x = cos(t*twopi/numt) * cos(s*twopi/numc);
  150. y = sin(t*twopi/numt) * cos(s*twopi/numc);
  151. z = sin(s*twopi/numc);
  152. glNormal3f(x, y, z);
  153. x = (rt + rc * cos(s*twopi/numc)) * cos(t*twopi/numt);
  154. y = (rt + rc * cos(s*twopi/numc)) * sin(t*twopi/numt);
  155. z = rc * sin(s*twopi/numc);
  156. glVertex3f(x, y, z);
  157. }
  158. }
  159. glEnd();
  160. }
  161. }
  162. UGL_LOCAL float Clamp(int iters_left, float t)
  163. {
  164. if (iters_left < 3)
  165. {
  166. return 0.0;
  167. }
  168. return (iters_left-2)*t/iters_left;
  169. }
  170. UGL_LOCAL void drawGL(void)
  171. {
  172. int i, j;
  173. for (i = 0; i < RINGS; i++)
  174. {
  175. if (iters[i]) {
  176. for (j = 0; j < 3; j++)
  177. {
  178. offsets[i][j] = Clamp(iters[i], offsets[i][j]);
  179. }
  180. angs[i] = Clamp(iters[i], angs[i]);
  181. iters[i]--;
  182. }
  183. }
  184. glPushMatrix();
  185. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  186. gluLookAt(0,0,10, 0,0,0, 0,1,0);
  187. for (i = 0; i < RINGS; i++)
  188. {
  189. if (rgb)
  190. {
  191. glColor3ubv(rgb_colors[i]);
  192. }
  193. else
  194. {
  195. glIndexi(mapped_colors[i]);
  196. }
  197. glPushMatrix();
  198. glTranslatef(dests[i][0]+offsets[i][0], dests[i][1]+offsets[i][1],
  199. dests[i][2]+offsets[i][2]);
  200. glRotatef(angs[i], rotAxis[i][0], rotAxis[i][1], rotAxis[i][2]);
  201. glCallList(theTorus);
  202. glPopMatrix();
  203. }
  204. glPopMatrix();
  205. glFlush();
  206. uglMesaSwapBuffers();
  207. }
  208. UGL_LOCAL float MyRand(void)
  209. {
  210. return 10.0 * ( (float) rand() / (float) RAND_MAX - 0.5 );
  211. }
  212. UGL_LOCAL void ReInit(void)
  213. {
  214. int i;
  215. float deviation;
  216. deviation = MyRand() / 2;
  217. deviation = deviation * deviation;
  218. for (i = 0; i < RINGS; i++)
  219. {
  220. offsets[i][0] = MyRand();
  221. offsets[i][1] = MyRand();
  222. offsets[i][2] = MyRand();
  223. angs[i] = 260.0 * MyRand();
  224. rotAxis[i][0] = MyRand();
  225. rotAxis[i][1] = MyRand();
  226. rotAxis[i][2] = MyRand();
  227. iters[i] = (deviation * MyRand() + 60.0);
  228. }
  229. }
  230. UGL_LOCAL void initGL(void)
  231. {
  232. float base, height;
  233. float aspect, x, y;
  234. int i;
  235. float top_y = 1.0;
  236. float bottom_y = 0.0;
  237. float top_z = 0.15;
  238. float bottom_z = 0.69;
  239. float spacing = 2.5;
  240. static float lmodel_ambient[] = {0.0, 0.0, 0.0, 0.0};
  241. static float lmodel_twoside[] = {GL_FALSE};
  242. static float lmodel_local[] = {GL_FALSE};
  243. static float light0_ambient[] = {0.1, 0.1, 0.1, 1.0};
  244. static float light0_diffuse[] = {1.0, 1.0, 1.0, 0.0};
  245. static float light0_position[] = {0.8660254, 0.5, 1, 0};
  246. static float light0_specular[] = {1.0, 1.0, 1.0, 0.0};
  247. static float bevel_mat_ambient[] = {0.0, 0.0, 0.0, 1.0};
  248. static float bevel_mat_shininess[] = {40.0};
  249. static float bevel_mat_specular[] = {1.0, 1.0, 1.0, 0.0};
  250. static float bevel_mat_diffuse[] = {1.0, 0.0, 0.0, 0.0};
  251. ReInit();
  252. for (i = 0; i < RINGS; i++)
  253. {
  254. rgb_colors[i][0] = rgb_colors[i][1] = rgb_colors[i][2] = 0;
  255. }
  256. rgb_colors[BLUERING][2] = 255;
  257. rgb_colors[REDRING][0] = 255;
  258. rgb_colors[GREENRING][1] = 255;
  259. rgb_colors[YELLOWRING][0] = 255;
  260. rgb_colors[YELLOWRING][1] = 255;
  261. mapped_colors[BLUERING] = COLOR_BLUE;
  262. mapped_colors[REDRING] = COLOR_RED;
  263. mapped_colors[GREENRING] = COLOR_GREEN;
  264. mapped_colors[YELLOWRING] = COLOR_YELLOW;
  265. mapped_colors[BLACKRING] = COLOR_BLACK;
  266. dests[BLUERING][0] = -spacing;
  267. dests[BLUERING][1] = top_y;
  268. dests[BLUERING][2] = top_z;
  269. dests[BLACKRING][0] = 0.0;
  270. dests[BLACKRING][1] = top_y;
  271. dests[BLACKRING][2] = top_z;
  272. dests[REDRING][0] = spacing;
  273. dests[REDRING][1] = top_y;
  274. dests[REDRING][2] = top_z;
  275. dests[YELLOWRING][0] = -spacing / 2.0;
  276. dests[YELLOWRING][1] = bottom_y;
  277. dests[YELLOWRING][2] = bottom_z;
  278. dests[GREENRING][0] = spacing / 2.0;
  279. dests[GREENRING][1] = bottom_y;
  280. dests[GREENRING][2] = bottom_z;
  281. base = 2.0;
  282. height = 2.0;
  283. theTorus = glGenLists(1);
  284. glNewList(theTorus, GL_COMPILE);
  285. FillTorus(0.1, 8, 1.0, 25);
  286. glEndList();
  287. x = (float)XSIZE;
  288. y = (float)YSIZE;
  289. aspect = x / y;
  290. glEnable(GL_CULL_FACE);
  291. glCullFace(GL_BACK);
  292. glEnable(GL_DEPTH_TEST);
  293. glClearDepth(1.0);
  294. if (rgb)
  295. {
  296. glClearColor(0.5, 0.5, 0.5, 0.0);
  297. glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
  298. glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
  299. glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
  300. glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
  301. glEnable(GL_LIGHT0);
  302. glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local);
  303. glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
  304. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  305. glEnable(GL_LIGHTING);
  306. glMaterialfv(GL_FRONT, GL_AMBIENT, bevel_mat_ambient);
  307. glMaterialfv(GL_FRONT, GL_SHININESS, bevel_mat_shininess);
  308. glMaterialfv(GL_FRONT, GL_SPECULAR, bevel_mat_specular);
  309. glMaterialfv(GL_FRONT, GL_DIFFUSE, bevel_mat_diffuse);
  310. glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
  311. glEnable(GL_COLOR_MATERIAL);
  312. glShadeModel(GL_SMOOTH);
  313. }
  314. else
  315. {
  316. glClearIndex(BACKGROUND);
  317. glShadeModel(GL_FLAT);
  318. }
  319. glMatrixMode(GL_PROJECTION);
  320. gluPerspective(45, 1.33, 0.1, 100.0);
  321. glMatrixMode(GL_MODELVIEW);
  322. }
  323. UGL_LOCAL void echoUse(void)
  324. {
  325. printf("tOlympic keys:\n");
  326. printf(" SPACE Reinitialize\n");
  327. printf(" ESC Exit\n");
  328. }
  329. UGL_LOCAL void readKey (UGL_WCHAR key)
  330. {
  331. switch(key)
  332. {
  333. case UGL_UNI_SPACE:
  334. ReInit();
  335. break;
  336. case UGL_UNI_ESCAPE:
  337. stopWex = 1;
  338. break;
  339. }
  340. }
  341. UGL_LOCAL void loopEvent(void)
  342. {
  343. UGL_EVENT event;
  344. UGL_INPUT_EVENT * pInputEvent;
  345. UGL_FOREVER
  346. {
  347. if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT)
  348. != UGL_STATUS_Q_EMPTY)
  349. {
  350. pInputEvent = (UGL_INPUT_EVENT *)&event;
  351. if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD &&
  352. pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN)
  353. readKey(pInputEvent->type.keyboard.key);
  354. }
  355. drawGL();
  356. if (stopWex)
  357. break;
  358. }
  359. }
  360. void windMLOlympic (UGL_BOOL windMLMode);
  361. void uglolympic (void)
  362. {
  363. taskSpawn("tOlympic", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLOlympic,
  364. 0,1,2,3,4,5,6,7,8,9);
  365. }
  366. void windMLOlympic(UGL_BOOL windMLMode)
  367. {
  368. UGL_INPUT_DEVICE_ID keyboardDevId;
  369. uglInitialize();
  370. uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId);
  371. if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0,
  372. (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK)
  373. {
  374. qId = uglEventQCreate (eventServiceId, 100);
  375. }
  376. else
  377. {
  378. eventServiceId = UGL_NULL;
  379. }
  380. if (windMLMode)
  381. umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE
  382. | UGL_MESA_WINDML_EXCLUSIVE, NULL);
  383. else
  384. umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL);
  385. if (umc == NULL)
  386. {
  387. uglDeinitialize();
  388. return;
  389. }
  390. uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH,
  391. UGL_MESA_FULLSCREEN_HEIGHT);
  392. uglMesaGetIntegerv(UGL_MESA_RGB, &rgb);
  393. initGL();
  394. echoUse();
  395. stopWex = 0;
  396. loopEvent();
  397. if (eventServiceId != UGL_NULL)
  398. uglEventQDestroy (eventServiceId, qId);
  399. uglMesaDestroyContext();
  400. uglDeinitialize();
  401. return;
  402. }