Clone of mesa.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

uglpoint.c 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. /* uglpoint.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. * Authors:
  28. * Stephane Raimbault <stephane.raimbault@windriver.com>
  29. */
  30. /*
  31. DESCRIPTION
  32. Draw a single point.
  33. */
  34. #include <stdio.h>
  35. #include <math.h>
  36. #include <ugl/ugl.h>
  37. #include <ugl/uglevent.h>
  38. #include <ugl/uglinput.h>
  39. #include <GL/uglmesa.h>
  40. #define DOUBLE_BUFFER GL_TRUE
  41. enum {
  42. BLACK = 0,
  43. RED,
  44. GREEN,
  45. BLUE,
  46. WHITE
  47. };
  48. UGL_LOCAL GLuint rgb;
  49. UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId;
  50. UGL_LOCAL UGL_EVENT_Q_ID qId;
  51. UGL_LOCAL UGL_MESA_CONTEXT umc;
  52. UGL_LOCAL GLint angleT;
  53. UGL_LOCAL void initGL (void)
  54. {
  55. /* By passed in RGB mode */
  56. uglMesaSetColor(BLACK, 0.0, 0.0, 0.0);
  57. uglMesaSetColor(RED, 1.0, 0.0, 0.0);
  58. uglMesaSetColor(GREEN, 0.0, 1.0, 0.0);
  59. uglMesaSetColor(BLUE, 0.0, 0.0, 1.0);
  60. uglMesaSetColor(WHITE, 1.0, 1.0, 1.0);
  61. glOrtho(0.0, 1.0, 0.0, 1.0, -20.0, 20.0);
  62. glClearColor(0.0, 0.0, 0.0, 0.0);
  63. glClearIndex(BLACK);
  64. }
  65. UGL_LOCAL void drawGL (void)
  66. {
  67. GLint i;
  68. GLfloat x, y;
  69. /* Avoid blinking in single buffer */
  70. if (DOUBLE_BUFFER)
  71. glClear(GL_COLOR_BUFFER_BIT);
  72. /* Random points */
  73. glBegin(GL_POINTS);
  74. (rgb) ? glColor3f(1.0, 0.0, 0.0): glIndexi(RED);
  75. for (i=0; i<150; i++)
  76. {
  77. x = rand() / (RAND_MAX+1.0);
  78. y = rand() / (RAND_MAX+1.0);
  79. glVertex2f(x, y);
  80. }
  81. (rgb) ? glColor3f(0.0, 1.0, 0.0): glIndexi(GREEN);
  82. for (i=0; i<150; i++)
  83. {
  84. x = (rand() / (RAND_MAX+1.0));
  85. y = (rand() / (RAND_MAX+1.0));
  86. glVertex2f(x, y);
  87. }
  88. (rgb) ? glColor3f(0.0, 0.0, 1.0): glIndexi(BLUE);
  89. glVertex2f(0.5,0.5);
  90. for (i=0; i<150; i++)
  91. {
  92. x = rand() / (RAND_MAX+1.0);
  93. y = rand() / (RAND_MAX+1.0);
  94. glVertex2f(x, y);
  95. }
  96. glEnd();
  97. /* Smooth triangle */
  98. glPushMatrix();
  99. glTranslatef(0.5, 0.5, 0);
  100. glRotatef(angleT, 1.0, -1.0, 0.0);
  101. angleT = angleT++ % 360;
  102. glBegin(GL_TRIANGLES);
  103. (rgb) ? glColor3f(1.0, 0.0, 0.0): glIndexi(RED);
  104. glVertex2f(0.75, 0.25);
  105. (rgb) ? glColor3f(0.0, 1.0, 0.0): glIndexi(GREEN);
  106. glVertex2f(0.75, 0.75);
  107. (rgb) ? glColor3f(0.0, 0.0, 1.0): glIndexi(BLUE);
  108. glVertex2f(0.25, 0.75);
  109. glEnd();
  110. glPopMatrix();
  111. /* Flush and swap */
  112. glFlush();
  113. uglMesaSwapBuffers();
  114. }
  115. /************************************************************************
  116. *
  117. * getEvent
  118. *
  119. * RETURNS: true or false
  120. *
  121. * NOMANUAL
  122. *
  123. */
  124. UGL_LOCAL int getEvent(void)
  125. {
  126. UGL_EVENT event;
  127. UGL_STATUS status;
  128. int retVal = 0;
  129. status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT);
  130. while (status != UGL_STATUS_Q_EMPTY)
  131. {
  132. UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event;
  133. if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN)
  134. retVal = 1;
  135. status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT);
  136. }
  137. return(retVal);
  138. }
  139. void windMLPoint (UGL_BOOL windMLMode);
  140. void uglpoint (void)
  141. {
  142. taskSpawn ("tPoint", 210, VX_FP_TASK, 100000,
  143. (FUNCPTR)windMLPoint, UGL_FALSE,1,2,3,4,5,6,7,8,9);
  144. }
  145. void windMLPoint (UGL_BOOL windMLMode)
  146. {
  147. GLubyte pPixels[4];
  148. GLsizei width, height;
  149. UGL_INPUT_DEVICE_ID keyboardDevId;
  150. angleT = 0;
  151. uglInitialize();
  152. uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId);
  153. if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0,
  154. (UGL_UINT32 *)&eventServiceId) == UGL_STATUS_OK)
  155. {
  156. qId = uglEventQCreate (eventServiceId, 100);
  157. }
  158. else
  159. {
  160. eventServiceId = UGL_NULL;
  161. }
  162. if (DOUBLE_BUFFER)
  163. {
  164. if (windMLMode)
  165. umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE
  166. | UGL_MESA_WINDML_EXCLUSIVE, NULL);
  167. else
  168. umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL);
  169. }
  170. else
  171. {
  172. if (windMLMode)
  173. umc = uglMesaCreateNewContext(UGL_MESA_SINGLE
  174. | UGL_MESA_WINDML_EXCLUSIVE, NULL);
  175. else
  176. umc = uglMesaCreateNewContext(UGL_MESA_SINGLE, NULL);
  177. }
  178. if (umc == NULL)
  179. {
  180. uglDeinitialize();
  181. return;
  182. }
  183. /* Fullscreen */
  184. uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH,
  185. UGL_MESA_FULLSCREEN_HEIGHT);
  186. /* RGB or CI ? */
  187. uglMesaGetIntegerv(UGL_MESA_RGB, &rgb);
  188. initGL();
  189. while (!getEvent())
  190. drawGL();
  191. uglMesaGetIntegerv(UGL_MESA_WIDTH, &width);
  192. uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height);
  193. printf ("glReadPixel return ");
  194. if (rgb)
  195. {
  196. glReadPixels(width/2, height/2,
  197. 1, 1, GL_RGB,
  198. GL_UNSIGNED_BYTE, pPixels);
  199. glFlush();
  200. printf ("R:%i G:%i B:%i (RGB)", pPixels[0], pPixels[1], pPixels[2]);
  201. }
  202. else
  203. {
  204. glReadPixels(width/2, height/2,
  205. 1, 1, GL_COLOR_INDEX,
  206. GL_UNSIGNED_BYTE, pPixels);
  207. glFlush();
  208. if (pPixels[0] == BLUE)
  209. printf ("BLUE (CI)");
  210. else
  211. printf ("%i (CI))", pPixels[0]);
  212. }
  213. printf(" for %ix%i\n", width/2, height/2);
  214. if (eventServiceId != UGL_NULL)
  215. uglEventQDestroy (eventServiceId, qId);
  216. uglMesaDestroyContext();
  217. uglDeinitialize();
  218. return;
  219. }