Clone of mesa.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

uglline.c 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* uglline.c - WindML/Mesa example program */
  2. /*
  3. * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
  4. *
  5. * Permission to use, copy, modify, distribute, and sell this software and
  6. * its documentation for any purpose is hereby granted without fee, provided
  7. * that (i) the above copyright notices and this permission notice appear in
  8. * all copies of the software and related documentation, and (ii) the name of
  9. * Silicon Graphics may not be used in any advertising or
  10. * publicity relating to the software without the specific, prior written
  11. * permission of Silicon Graphics.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
  14. * ANY KIND,
  15. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  16. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  17. *
  18. * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
  19. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  22. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  23. * OF THIS SOFTWARE.
  24. */
  25. /*
  26. modification history
  27. --------------------
  28. 01a,jun01,sra Ported to UGL/Mesa and modifications
  29. */
  30. /*
  31. DESCRIPTION
  32. Draw circular lines
  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 YELLOW (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 GLboolean mode1, mode2;
  53. UGL_LOCAL GLint size;
  54. UGL_LOCAL GLfloat pntA[3] = {
  55. -10.0, 0.0, 0.0
  56. };
  57. UGL_LOCAL GLfloat pntB[3] = {
  58. -5.0, 0.0, 0.0
  59. };
  60. UGL_LOCAL GLint angleA;
  61. UGL_LOCAL void initGL (void)
  62. {
  63. GLint i;
  64. uglMesaSetColor(BLACK, 0.0, 0.0, 0.0);
  65. uglMesaSetColor(YELLOW, 1.0, 1.0, 0.0);
  66. uglMesaSetColor(GREEN, 0.0, 1.0, 0.0);
  67. uglMesaSetColor(BLUE, 0.0, 0.0, 1.0);
  68. for (i = 0; i < 16; i++)
  69. {
  70. uglMesaSetColor(CI_OFFSET+i, i/15.0, i/15.0, 0.0);
  71. }
  72. glClearColor(0.0, 0.0, 0.0, 0.0);
  73. glClearIndex(BLACK);
  74. glMatrixMode(GL_PROJECTION);
  75. glLoadIdentity();
  76. glOrtho(-10, 10, -10, 10, -10.0, 10.0);
  77. glMatrixMode(GL_MODELVIEW);
  78. glLineStipple(1, 0xF0E0);
  79. glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  80. mode1 = GL_FALSE;
  81. mode2 = GL_FALSE;
  82. size = 1;
  83. }
  84. UGL_LOCAL void drawGL (void)
  85. {
  86. GLint ci, i;
  87. glClear(GL_COLOR_BUFFER_BIT);
  88. glLineWidth(size);
  89. if (mode1) {
  90. glEnable(GL_LINE_STIPPLE);
  91. } else {
  92. glDisable(GL_LINE_STIPPLE);
  93. }
  94. if (mode2) {
  95. ci = CI_OFFSET;
  96. glEnable(GL_LINE_SMOOTH);
  97. glEnable(GL_BLEND);
  98. } else {
  99. ci = YELLOW;
  100. glDisable(GL_LINE_SMOOTH);
  101. glDisable(GL_BLEND);
  102. }
  103. glPushMatrix();
  104. glRotatef(angleA, 1, 0, 1);
  105. angleA = angleA++ % 360;
  106. for (i = 0; i < 360; i += 5) {
  107. glRotatef(5.0, 0, 0, 1);
  108. glColor3f(1.0, 1.0, 0.0);
  109. glBegin(GL_LINE_STRIP);
  110. glVertex3fv(pntA);
  111. glVertex3fv(pntB);
  112. glEnd();
  113. glPointSize(1);
  114. glColor3f(0.0, 1.0, 0.0);
  115. glBegin(GL_POINTS);
  116. glVertex3fv(pntA);
  117. glVertex3fv(pntB);
  118. glEnd();
  119. }
  120. glPopMatrix();
  121. glFlush();
  122. uglMesaSwapBuffers();
  123. }
  124. UGL_LOCAL void echoUse(void)
  125. {
  126. printf("tLine keys:\n");
  127. printf(" b Blending/antialiasing\n");
  128. printf(" n Line stipple\n");
  129. printf(" Up/Down Pixel size\n");
  130. printf(" ESC Exit\n");
  131. }
  132. UGL_LOCAL void readKey (UGL_WCHAR key)
  133. {
  134. switch(key)
  135. {
  136. case 'n':
  137. mode1 = (mode1) ? GL_FALSE: GL_TRUE;
  138. break;
  139. case 'b':
  140. mode2 = (mode2) ? GL_FALSE: GL_TRUE;
  141. break;
  142. case UGL_UNI_DOWN_ARROW:
  143. if(size>0)
  144. size--;
  145. break;
  146. case UGL_UNI_UP_ARROW:
  147. size++;
  148. break;
  149. case UGL_UNI_ESCAPE:
  150. stopWex = UGL_TRUE;
  151. break;
  152. }
  153. }
  154. UGL_LOCAL void loopEvent(void)
  155. {
  156. UGL_EVENT event;
  157. UGL_INPUT_EVENT * pInputEvent;
  158. UGL_FOREVER
  159. {
  160. if (uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT)
  161. != UGL_STATUS_Q_EMPTY)
  162. {
  163. pInputEvent = (UGL_INPUT_EVENT *)&event;
  164. if (pInputEvent->header.type == UGL_EVENT_TYPE_KEYBOARD &&
  165. pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN)
  166. readKey(pInputEvent->type.keyboard.key);
  167. }
  168. drawGL();
  169. if (stopWex)
  170. break;
  171. }
  172. }
  173. void windMLLine (UGL_BOOL windMLMode);
  174. void uglline (void)
  175. {
  176. taskSpawn("tLine", 210, VX_FP_TASK, 100000, (FUNCPTR)windMLLine,
  177. UGL_FALSE,1,2,3,4,5,6,7,8,9);
  178. }
  179. void windMLLine(UGL_BOOL windMLMode)
  180. {
  181. UGL_INPUT_DEVICE_ID keyboardDevId;
  182. angleA = 0;
  183. uglInitialize();
  184. uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId);
  185. uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId);
  186. qId = uglEventQCreate (eventServiceId, 100);
  187. /* Double buffer */
  188. if (windMLMode)
  189. umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE
  190. | UGL_MESA_WINDML_EXCLUSIVE, NULL);
  191. else
  192. umc = uglMesaCreateNewContext(UGL_MESA_DOUBLE, NULL);
  193. if (umc == NULL)
  194. {
  195. uglDeinitialize();
  196. return;
  197. }
  198. /* Fullscreen */
  199. uglMesaMakeCurrentContext(umc, 0, 0, UGL_MESA_FULLSCREEN_WIDTH,
  200. UGL_MESA_FULLSCREEN_HEIGHT);
  201. uglMesaGetIntegerv(UGL_MESA_RGB, &rgb);
  202. initGL();
  203. echoUse();
  204. stopWex = UGL_FALSE;
  205. loopEvent();
  206. uglEventQDestroy(eventServiceId, qId);
  207. uglMesaDestroyContext();
  208. uglDeinitialize();
  209. return;
  210. }