Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /* Copyright (c) Mark J. Kilgard, 1994. */
  2. /*
  3. * (c) Copyright 1993, Silicon Graphics, Inc.
  4. * ALL RIGHTS RESERVED
  5. * Permission to use, copy, modify, and distribute this software for
  6. * any purpose and without fee is hereby granted, provided that the above
  7. * copyright notice appear in all copies and that both the copyright notice
  8. * and this permission notice appear in supporting documentation, and that
  9. * the name of Silicon Graphics, Inc. not be used in advertising
  10. * or publicity pertaining to distribution of the software without specific,
  11. * written prior permission.
  12. *
  13. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  17. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  22. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25. *
  26. * US Government Users Restricted Rights
  27. * Use, duplication, or disclosure by the Government is subject to
  28. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  29. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  30. * clause at DFARS 252.227-7013 and/or in similar or successor
  31. * clauses in the FAR or the DOD or NASA FAR Supplement.
  32. * Unpublished-- rights reserved under the copyright laws of the
  33. * United States. Contractor/manufacturer is Silicon Graphics,
  34. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  35. *
  36. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  37. */
  38. /* Original name: accanti.c
  39. *
  40. * Conversion to UGL/Mesa by Stephane Raimbault
  41. */
  42. #include <stdio.h>
  43. #include <math.h>
  44. #include <ugl/ugl.h>
  45. #include <ugl/uglevent.h>
  46. #include <ugl/uglinput.h>
  47. #include <GL/uglmesa.h>
  48. #include <GL/uglglutshapes.h>
  49. #include "../book/jitter.h"
  50. UGL_LOCAL UGL_EVENT_SERVICE_ID eventServiceId;
  51. UGL_LOCAL UGL_EVENT_Q_ID qId;
  52. UGL_LOCAL UGL_MESA_CONTEXT umc;
  53. /* Initialize lighting and other values.
  54. */
  55. UGL_LOCAL void initGL(GLsizei w, GLsizei h)
  56. {
  57. GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
  58. GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
  59. GLfloat light_position[] = { 0.0, 0.0, 10.0, 1.0 };
  60. GLfloat lm_ambient[] = { 0.2, 0.2, 0.2, 1.0 };
  61. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  62. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  63. glMaterialf(GL_FRONT, GL_SHININESS, 50.0);
  64. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  65. glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lm_ambient);
  66. glEnable(GL_LIGHTING);
  67. glEnable(GL_LIGHT0);
  68. glDepthFunc(GL_LESS);
  69. glEnable(GL_DEPTH_TEST);
  70. glShadeModel (GL_FLAT);
  71. glClearColor(0.0, 0.0, 0.0, 0.0);
  72. glClearAccum(0.0, 0.0, 0.0, 0.0);
  73. glMatrixMode(GL_PROJECTION);
  74. glLoadIdentity();
  75. if (w <= h)
  76. glOrtho (-2.25, 2.25, -2.25*h/w, 2.25*h/w, -10.0, 10.0);
  77. else
  78. glOrtho (-2.25*w/h, 2.25*w/h, -2.25, 2.25, -10.0, 10.0);
  79. glMatrixMode(GL_MODELVIEW);
  80. }
  81. UGL_LOCAL void displayObjects(void)
  82. {
  83. GLfloat torus_diffuse[] = { 0.7, 0.7, 0.0, 1.0 };
  84. GLfloat cube_diffuse[] = { 0.0, 0.7, 0.7, 1.0 };
  85. GLfloat sphere_diffuse[] = { 0.7, 0.0, 0.7, 1.0 };
  86. GLfloat octa_diffuse[] = { 0.7, 0.4, 0.4, 1.0 };
  87. glPushMatrix ();
  88. glRotatef (30.0, 1.0, 0.0, 0.0);
  89. glPushMatrix ();
  90. glTranslatef (-0.80, 0.35, 0.0);
  91. glRotatef (100.0, 1.0, 0.0, 0.0);
  92. glMaterialfv(GL_FRONT, GL_DIFFUSE, torus_diffuse);
  93. glutSolidTorus (0.275, 0.85, 16, 16);
  94. glPopMatrix ();
  95. glPushMatrix ();
  96. glTranslatef (-0.75, -0.50, 0.0);
  97. glRotatef (45.0, 0.0, 0.0, 1.0);
  98. glRotatef (45.0, 1.0, 0.0, 0.0);
  99. glMaterialfv(GL_FRONT, GL_DIFFUSE, cube_diffuse);
  100. glutSolidCube (1.5);
  101. glPopMatrix ();
  102. glPushMatrix ();
  103. glTranslatef (0.75, 0.60, 0.0);
  104. glRotatef (30.0, 1.0, 0.0, 0.0);
  105. glMaterialfv(GL_FRONT, GL_DIFFUSE, sphere_diffuse);
  106. glutSolidSphere (1.0, 16, 16);
  107. glPopMatrix ();
  108. glPushMatrix ();
  109. glTranslatef (0.70, -0.90, 0.25);
  110. glMaterialfv(GL_FRONT, GL_DIFFUSE, octa_diffuse);
  111. glutSolidOctahedron ();
  112. glPopMatrix ();
  113. glPopMatrix ();
  114. }
  115. #define ACSIZE 8
  116. UGL_LOCAL void drawGL(void)
  117. {
  118. GLint viewport[4];
  119. int jitter;
  120. glGetIntegerv (GL_VIEWPORT, viewport);
  121. glClear(GL_ACCUM_BUFFER_BIT);
  122. for (jitter = 0; jitter < ACSIZE; jitter++)
  123. {
  124. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  125. glPushMatrix ();
  126. /* Note that 4.5 is the distance in world space between
  127. * left and right and bottom and top.
  128. * This formula converts fractional pixel movement to
  129. * world coordinates.
  130. */
  131. glTranslatef (j8[jitter].x*4.5/viewport[2],
  132. j8[jitter].y*4.5/viewport[3], 0.0);
  133. displayObjects ();
  134. glPopMatrix ();
  135. glAccum(GL_ACCUM, 1.0/ACSIZE);
  136. }
  137. glAccum (GL_RETURN, 1.0);
  138. glFlush();
  139. uglMesaSwapBuffers();
  140. }
  141. UGL_LOCAL int getEvent(void)
  142. {
  143. UGL_EVENT event;
  144. UGL_STATUS status;
  145. int retVal = 0;
  146. status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT);
  147. while (status != UGL_STATUS_Q_EMPTY)
  148. {
  149. UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event;
  150. if (pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN)
  151. retVal = 1;
  152. status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT);
  153. }
  154. return(retVal);
  155. }
  156. void windMLAccum (UGL_BOOL windMLMode);
  157. void uglaccum (void)
  158. {
  159. taskSpawn("tAccum", 210, VX_FP_TASK, 100000,
  160. (FUNCPTR)windMLAccum,UGL_FALSE,1,2,3,4,5,6,7,8,9);
  161. }
  162. void windMLAccum (UGL_BOOL windMLMode)
  163. {
  164. UGL_INPUT_DEVICE_ID keyboardDevId;
  165. GLsizei width, height;
  166. uglInitialize();
  167. uglDriverFind (UGL_KEYBOARD_TYPE, 0, (UGL_UINT32 *)&keyboardDevId);
  168. uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId);
  169. qId = uglEventQCreate (eventServiceId, 100);
  170. if (windMLMode)
  171. umc = uglMesaCreateNewContextExt(UGL_MESA_DOUBLE
  172. | UGL_MESA_WINDML_EXCLUSIVE,
  173. 16,
  174. 0,
  175. 8,8,8,0,
  176. NULL);
  177. else
  178. umc = uglMesaCreateNewContextExt(UGL_MESA_DOUBLE,
  179. 16,
  180. 0,
  181. 8,8,8,0,
  182. NULL);
  183. if (umc == NULL)
  184. {
  185. uglDeinitialize();
  186. return;
  187. }
  188. /* Fullscreen */
  189. uglMesaMakeCurrentContext(umc, 0, 0,
  190. UGL_MESA_FULLSCREEN_WIDTH,
  191. UGL_MESA_FULLSCREEN_HEIGHT);
  192. uglMesaGetIntegerv(UGL_MESA_WIDTH, &width);
  193. uglMesaGetIntegerv(UGL_MESA_HEIGHT, &height);
  194. initGL(width, height);
  195. drawGL();
  196. while (!getEvent());
  197. uglEventQDestroy (eventServiceId, qId);
  198. uglMesaDestroyContext();
  199. uglDeinitialize();
  200. return;
  201. }