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.

uglicotorus.c 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /* uglicotorus.c - WindML/Mesa example program */
  2. /* Copyright (C) 2001 by Wind River Systems, Inc */
  3. /*
  4. * Mesa 3-D graphics library
  5. * Version: 3.5
  6. *
  7. * The MIT License
  8. * Permission is hereby granted, free of charge, to any person obtaining a
  9. * copy of this software and associated documentation files (the "Software"),
  10. * to deal in the Software without restriction, including without limitation
  11. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  12. * and/or sell copies of the Software, and to permit persons to whom the
  13. * Software is furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included
  16. * in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  21. * THE AUTHORS OR COPYRIGHT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  23. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  24. * DEALINGS IN THE SOFTWARE.
  25. */
  26. /*
  27. modification history
  28. --------------------
  29. 01a,jun01,sra
  30. */
  31. #include <stdio.h>
  32. #include <math.h>
  33. #include <ugl/uglevent.h>
  34. #include <ugl/uglinput.h>
  35. #include <ugl/uglucode.h>
  36. #include <GL/uglmesa.h>
  37. #include <GL/glu.h>
  38. /* Need GLUT_SHAPES */
  39. #include <GL/uglglutshapes.h>
  40. UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId;
  41. UGL_LOCAL UGL_EVENT_Q_ID qId;
  42. UGL_LOCAL UGL_MESA_CONTEXT umc;
  43. UGL_LOCAL volatile UGL_BOOL stopWex;
  44. UGL_LOCAL GLfloat angle;
  45. UGL_LOCAL GLboolean chaos_on;
  46. UGL_LOCAL GLboolean color_on;
  47. UGL_LOCAL GLuint theIco, theTorus, theSphere, theCube;
  48. UGL_LOCAL void initGL
  49. (
  50. int w,
  51. int h
  52. )
  53. {
  54. glViewport(0,0,(GLsizei)w,(GLsizei)h);
  55. glMatrixMode(GL_PROJECTION);
  56. glLoadIdentity();
  57. gluPerspective(60.0,(GLfloat)w/(GLfloat)h,1.0,60.0);
  58. glMatrixMode(GL_MODELVIEW);
  59. glLoadIdentity();
  60. gluLookAt(0.0,0.0,25.0,0.0,0.0,0.0,0.0,1.0,0.0);
  61. glClearColor(0.0,0.0,0.0,0.0);
  62. glEnable(GL_DEPTH_TEST);
  63. glEnable(GL_LIGHTING);
  64. glEnable(GL_LIGHT0);
  65. glEnable(GL_COLOR_MATERIAL);
  66. theIco = glGenLists(1);
  67. glNewList(theIco, GL_COMPILE);
  68. glutSolidIcosahedron();
  69. glEndList();
  70. theTorus = glGenLists(1);
  71. glNewList(theTorus, GL_COMPILE);
  72. glutSolidTorus(0.2,1.0,10,10);
  73. glEndList();
  74. theSphere = glGenLists(1);
  75. glNewList(theSphere, GL_COMPILE);
  76. glutSolidSphere(2.5,20,20);
  77. glEndList();
  78. theCube = glGenLists(1);
  79. glNewList(theCube, GL_COMPILE);
  80. glutSolidCube(4.0);
  81. glEndList();
  82. }
  83. UGL_LOCAL void createIcoToruses
  84. (
  85. int i
  86. )
  87. {
  88. glPushMatrix();
  89. glRotatef(angle,1.0,1.0,1.0);
  90. glCallList(theIco);
  91. switch (i)
  92. {
  93. case 9 :
  94. glColor3f(1.0,0.0,0.0);
  95. break;
  96. case 0 :
  97. glColor3f(1.0,0.1,0.7);
  98. break;
  99. case 1 :
  100. glColor3f(1.0,0.0,1.0);
  101. break;
  102. case 2 :
  103. glColor3f(0.0,0.0,1.0);
  104. break;
  105. case 3 :
  106. glColor3f(0.0,0.5,1.0);
  107. break;
  108. case 4 :
  109. glColor3f(0.0,1.0,0.7);
  110. break;
  111. case 5 :
  112. glColor3f(0.0,1.0,0.0);
  113. break;
  114. case 6 :
  115. glColor3f(0.5,1.0,0.0);
  116. break;
  117. case 7 :
  118. glColor3f(1.0,1.0,0.0);
  119. break;
  120. case 8 :
  121. glColor3f(1.0,0.5,0.0);
  122. break;
  123. }
  124. glRotatef(angle,1.0,1.0,1.0);
  125. glCallList(theTorus);
  126. glRotatef(-2*angle,1.0,1.0,1.0);
  127. glCallList(theTorus);
  128. glPopMatrix();
  129. }
  130. UGL_LOCAL void drawGL (void)
  131. {
  132. int i;
  133. if (color_on)
  134. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  135. else
  136. glClear(GL_DEPTH_BUFFER_BIT);
  137. glPushMatrix();
  138. if (chaos_on)
  139. glRotatef(angle,1.0,1.0,1.0);
  140. glPushMatrix();
  141. glRotatef(angle,1.0,1.0,1.0);
  142. glColor3f(1.0,0.5,0.0);
  143. glCallList(theSphere);
  144. glColor3f(1.0,0.0,0.0);
  145. glCallList(theCube);
  146. glPopMatrix();
  147. glRotatef(-angle,0.0,0.0,1.0);
  148. glPushMatrix();
  149. /* draw ten icosahedrons */
  150. for (i = 0; i < 10; i++)
  151. {
  152. glPushMatrix();
  153. glRotatef(36*i,0.0,0.0,1.0);
  154. glTranslatef(10.0,0.0,0.0);
  155. glRotatef(2*angle,0.0,1.0,0.0);
  156. glTranslatef(0.0,0.0,2.0);
  157. createIcoToruses(i);
  158. glPopMatrix();
  159. }
  160. glPopMatrix();
  161. glPopMatrix();
  162. uglMesaSwapBuffers();
  163. angle += 1.0;
  164. }
  165. UGL_LOCAL void echoUse(void)
  166. {
  167. printf("tIcoTorus keys:\n");
  168. printf(" c Toggle color buffer clear\n");
  169. printf(" SPACE Toggle chaos mode\n");
  170. printf(" ESC Exit\n");
  171. }
  172. UGL_LOCAL void readKey (UGL_WCHAR key)
  173. {
  174. switch(key)
  175. {
  176. case 'c':
  177. color_on = !color_on;
  178. break;
  179. case UGL_UNI_SPACE:
  180. chaos_on = !chaos_on;
  181. break;
  182. case UGL_UNI_ESCAPE:
  183. stopWex = UGL_TRUE;
  184. break;
  185. }
  186. }
  187. UGL_LOCAL void loopEvent(void)
  188. {
  189. UGL_EVENT event;
  190. UGL_INPUT_EVENT * pInputEvent;
  191. UGL_FOREVER
  192. {
  193. if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT)
  194. != UGL_STATUS_Q_EMPTY)
  195. {
  196. pInputEvent = (UGL_INPUT_EVENT *)&event;
  197. if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD &&
  198. pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN)
  199. readKey(pInputEvent->type.keyboard.key);
  200. }
  201. drawGL();
  202. if (stopWex)
  203. break;
  204. }
  205. }
  206. void windMLIcoTorus (UGL_BOOL windMLMode);
  207. void uglicotorus (void)
  208. {
  209. taskSpawn ("tIcoTorus", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLIcoTorus,
  210. UGL_FALSE,1,2,3,4,5,6,7,8,9);
  211. }
  212. void windMLIcoTorus (UGL_BOOL windMLMode)
  213. {
  214. GLsizei width, height;
  215. UGL_INPUT_DEVICE_ID keyboardDevId;
  216. angle = 0.0;
  217. chaos_on = GL_TRUE;
  218. color_on = GL_TRUE;
  219. uglInitialize ();
  220. uglDriverFind (UGL_KEYBOARD_TYPE, 0,
  221. (UGL_UINT32 *)&keyboardDevId);
  222. if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0,
  223. (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK)
  224. {
  225. qId = uglEventQCreate (eventServiceId, 100);
  226. }
  227. else
  228. {
  229. eventServiceId = UGL_NULL;
  230. }
  231. /* Double buffering */
  232. if (windMLMode)
  233. umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE
  234. | UGL_MESA_WINDML_EXCLUSIVE, NULL);
  235. else
  236. umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL);
  237. if (umc == NULL)
  238. {
  239. uglDeinitialize ();
  240. return;
  241. }
  242. uglMesaMakeCurrentContext (umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH,
  243. UGL_MESA_FULLSCREEN_HEIGHT);
  244. uglMesaGetIntegerv(UGL_MESA_WIDTH, &width);
  245. uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height);
  246. initGL (width, height);
  247. echoUse();
  248. stopWex = UGL_FALSE;
  249. loopEvent();
  250. if (eventServiceId != UGL_NULL)
  251. uglEventQDestroy (eventServiceId, qId);
  252. uglMesaDestroyContext ();
  253. uglDeinitialize ();
  254. return;
  255. }