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.

uglflip.c 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* uglflip.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 triangle and flip the screen
  33. */
  34. #include <stdio.h>
  35. #include <math.h>
  36. #include <ugl/ugl.h>
  37. #include <ugl/uglucode.h>
  38. #include <ugl/uglevent.h>
  39. #include <ugl/uglinput.h>
  40. #include <GL/uglmesa.h>
  41. #include <GL/glu.h>
  42. #define BLACK (0)
  43. #define RED (1)
  44. #define GREEN (2)
  45. #define BLUE (3)
  46. #define CI_OFFSET 4
  47. UGL_LOCAL GLuint rgb;
  48. UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId;
  49. UGL_LOCAL UGL_EVENT_Q_ID qId;
  50. UGL_LOCAL volatile UGL_BOOL stopWex;
  51. UGL_LOCAL UGL_MESA_CONTEXT umc;
  52. UGL_LOCAL void initGL (void)
  53. {
  54. uglMesaSetColor(BLACK, 0.0, 0.0, 0.0);
  55. uglMesaSetColor(RED, 1.0, 0.3, 0.3);
  56. uglMesaSetColor(GREEN, 0.3, 1.0, 0.3);
  57. uglMesaSetColor(BLUE, 0.3, 0.3, 1.0);
  58. glClearColor(0.0, 0.0, 0.0, 0.0);
  59. glClearIndex(BLACK);
  60. glMatrixMode(GL_PROJECTION);
  61. glLoadIdentity();
  62. glMatrixMode(GL_MODELVIEW);
  63. }
  64. UGL_LOCAL void drawGL (void)
  65. {
  66. glClear(GL_COLOR_BUFFER_BIT);
  67. glBegin(GL_TRIANGLES);
  68. (rgb) ? glColor3f(1.0, 0.3, 0.3) : glIndexi(RED);
  69. glVertex2f(0.75, -0.50);
  70. (rgb) ? glColor3f(0.3, 1.0, 0.3) : glIndexi(GREEN);
  71. glVertex2f(0.0, 0.75);
  72. (rgb) ? glColor3f(0.3, 0.3, 1.0) : glIndexi(BLUE);
  73. glVertex2f(-0.75, -0.50);
  74. glEnd();
  75. glBegin(GL_LINES);
  76. (rgb) ? glColor3f(1.0, 0.3, 0.3) : glIndexi(RED);
  77. glVertex2f(-1.0, 1.0);
  78. (rgb) ? glColor3f(0.3, 0.3, 1.0) : glIndexi(BLUE);
  79. glVertex2f(1.0, -1.0);
  80. glEnd();
  81. glFlush();
  82. uglMesaSwapBuffers();
  83. }
  84. UGL_LOCAL void echoUse(void)
  85. {
  86. printf("tFlip keys:\n");
  87. printf(" d Toggle dithering\n");
  88. printf(" up Reduce the window\n");
  89. printf(" down Enlarge the window\n");
  90. printf(" page up Y==0 is the bottom line and increases upward\n");
  91. printf(" page down Y==0 is the bottom line and increases downward\n");
  92. printf(" ESC Exit\n");
  93. }
  94. UGL_LOCAL void readKey (UGL_WCHAR key)
  95. {
  96. switch(key)
  97. {
  98. case UGL_UNI_UP_ARROW:
  99. uglMesaResizeWindow(8, 8);
  100. break;
  101. case UGL_UNI_DOWN_ARROW:
  102. glDrawBuffer(GL_FRONT_LEFT);
  103. glClear(GL_COLOR_BUFFER_BIT);
  104. glDrawBuffer(GL_BACK_LEFT);
  105. uglMesaResizeWindow(-8, -8);
  106. break;
  107. case UGL_UNI_PAGE_UP:
  108. uglMesaPixelStore(UGL_MESA_Y_UP, GL_TRUE);
  109. break;
  110. case UGL_UNI_PAGE_DOWN:
  111. uglMesaPixelStore(UGL_MESA_Y_UP, GL_FALSE);
  112. break;
  113. case UGL_UNI_ESCAPE:
  114. stopWex = UGL_TRUE;
  115. break;
  116. case 'd':
  117. if (glIsEnabled(GL_DITHER))
  118. glDisable(GL_DITHER);
  119. else
  120. glEnable(GL_DITHER);
  121. break;
  122. }
  123. }
  124. UGL_LOCAL void loopEvent(void)
  125. {
  126. UGL_EVENT event;
  127. UGL_INPUT_EVENT * pInputEvent;
  128. drawGL();
  129. UGL_FOREVER
  130. {
  131. if (uglEventGet (qId, &event, sizeof (event), UGL_WAIT_FOREVER)
  132. != UGL_STATUS_Q_EMPTY)
  133. {
  134. pInputEvent = (UGL_INPUT_EVENT *)&event;
  135. if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD &&
  136. pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN)
  137. {
  138. readKey(pInputEvent->type.keyboard.key);
  139. drawGL();
  140. }
  141. }
  142. if (stopWex)
  143. break;
  144. }
  145. }
  146. void windMLFlip (UGL_BOOL windMLMode);
  147. void uglflip (void)
  148. {
  149. taskSpawn ("tFlip", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLFlip,
  150. UGL_FALSE,1,2,3,4,5,6,7,8,9);
  151. }
  152. void windMLFlip (UGL_BOOL windMLMode)
  153. {
  154. UGL_INPUT_DEVICE_ID keyboardDevId;
  155. uglInitialize();
  156. uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId);
  157. uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId);
  158. qId = uglEventQCreate (eventServiceId, 100);
  159. if (windMLMode)
  160. umc = uglMesaCreateNewContext(UGL_MESA_SINGLE
  161. | UGL_MESA_WINDML_EXCLUSIVE, NULL);
  162. else
  163. umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE_SOFTWARE, NULL);
  164. if (umc == NULL)
  165. {
  166. uglDeinitialize();
  167. return;
  168. }
  169. uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH,
  170. UGL_MESA_FULLSCREEN_HEIGHT);
  171. uglMesaGetIntegerv(UGL_MESA_RGB, &rgb);
  172. initGL();
  173. echoUse();
  174. stopWex = UGL_FALSE;
  175. loopEvent();
  176. uglEventQDestroy (eventServiceId, qId);
  177. uglMesaDestroyContext();
  178. uglDeinitialize();
  179. return;
  180. }