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.

varray.c 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * Copyright (c) 1993-1997, Silicon Graphics, Inc.
  3. * ALL RIGHTS RESERVED
  4. * Permission to use, copy, modify, and distribute this software for
  5. * any purpose and without fee is hereby granted, provided that the above
  6. * copyright notice appear in all copies and that both the copyright notice
  7. * and this permission notice appear in supporting documentation, and that
  8. * the name of Silicon Graphics, Inc. not be used in advertising
  9. * or publicity pertaining to distribution of the software without specific,
  10. * written prior permission.
  11. *
  12. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  16. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  21. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24. *
  25. * US Government Users Restricted Rights
  26. * Use, duplication, or disclosure by the Government is subject to
  27. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29. * clause at DFARS 252.227-7013 and/or in similar or successor
  30. * clauses in the FAR or the DOD or NASA FAR Supplement.
  31. * Unpublished-- rights reserved under the copyright laws of the
  32. * United States. Contractor/manufacturer is Silicon Graphics,
  33. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  34. *
  35. * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
  36. */
  37. /*
  38. * varray.c
  39. * This program demonstrates vertex arrays.
  40. */
  41. #include <GL/glut.h>
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #ifdef GL_VERSION_1_1
  45. #define POINTER 1
  46. #define INTERLEAVED 2
  47. #define DRAWARRAY 1
  48. #define ARRAYELEMENT 2
  49. #define DRAWELEMENTS 3
  50. int setupMethod = POINTER;
  51. int derefMethod = DRAWARRAY;
  52. static void setupPointers(void)
  53. {
  54. static GLint vertices[] = {25, 25,
  55. 100, 325,
  56. 175, 25,
  57. 175, 325,
  58. 250, 25,
  59. 325, 325};
  60. static GLfloat colors[] = {1.0, 0.2, 0.2,
  61. 0.2, 0.2, 1.0,
  62. 0.8, 1.0, 0.2,
  63. 0.75, 0.75, 0.75,
  64. 0.35, 0.35, 0.35,
  65. 0.5, 0.5, 0.5};
  66. glEnableClientState (GL_VERTEX_ARRAY);
  67. glEnableClientState (GL_COLOR_ARRAY);
  68. glVertexPointer (2, GL_INT, 0, vertices);
  69. glColorPointer (3, GL_FLOAT, 0, colors);
  70. }
  71. static void setupInterleave(void)
  72. {
  73. static GLfloat intertwined[] =
  74. {1.0, 0.2, 1.0, 100.0, 100.0, 0.0,
  75. 1.0, 0.2, 0.2, 0.0, 200.0, 0.0,
  76. 1.0, 1.0, 0.2, 100.0, 300.0, 0.0,
  77. 0.2, 1.0, 0.2, 200.0, 300.0, 0.0,
  78. 0.2, 1.0, 1.0, 300.0, 200.0, 0.0,
  79. 0.2, 0.2, 1.0, 200.0, 100.0, 0.0};
  80. glInterleavedArrays (GL_C3F_V3F, 0, intertwined);
  81. }
  82. static void init(void)
  83. {
  84. glClearColor (0.0, 0.0, 0.0, 0.0);
  85. glShadeModel (GL_SMOOTH);
  86. setupPointers ();
  87. }
  88. static void display(void)
  89. {
  90. glClear (GL_COLOR_BUFFER_BIT);
  91. if (derefMethod == DRAWARRAY)
  92. glDrawArrays (GL_TRIANGLES, 0, 6);
  93. else if (derefMethod == ARRAYELEMENT) {
  94. glBegin (GL_TRIANGLES);
  95. glArrayElement (2);
  96. glArrayElement (3);
  97. glArrayElement (5);
  98. glEnd ();
  99. }
  100. else if (derefMethod == DRAWELEMENTS) {
  101. GLuint indices[4] = {0, 1, 3, 4};
  102. glDrawElements (GL_POLYGON, 4, GL_UNSIGNED_INT, indices);
  103. }
  104. glFlush ();
  105. }
  106. static void reshape (int w, int h)
  107. {
  108. glViewport (0, 0, (GLsizei) w, (GLsizei) h);
  109. glMatrixMode (GL_PROJECTION);
  110. glLoadIdentity ();
  111. gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h);
  112. }
  113. /* ARGSUSED2 */
  114. static void mouse (int button, int state, int x, int y)
  115. {
  116. switch (button) {
  117. case GLUT_LEFT_BUTTON:
  118. if (state == GLUT_DOWN) {
  119. if (setupMethod == POINTER) {
  120. setupMethod = INTERLEAVED;
  121. setupInterleave();
  122. }
  123. else if (setupMethod == INTERLEAVED) {
  124. setupMethod = POINTER;
  125. setupPointers();
  126. }
  127. glutPostRedisplay();
  128. }
  129. break;
  130. case GLUT_MIDDLE_BUTTON:
  131. case GLUT_RIGHT_BUTTON:
  132. if (state == GLUT_DOWN) {
  133. if (derefMethod == DRAWARRAY)
  134. derefMethod = ARRAYELEMENT;
  135. else if (derefMethod == ARRAYELEMENT)
  136. derefMethod = DRAWELEMENTS;
  137. else if (derefMethod == DRAWELEMENTS)
  138. derefMethod = DRAWARRAY;
  139. glutPostRedisplay();
  140. }
  141. break;
  142. default:
  143. break;
  144. }
  145. }
  146. /* ARGSUSED1 */
  147. static void keyboard(unsigned char key, int x, int y)
  148. {
  149. switch (key) {
  150. case 27:
  151. exit(0);
  152. break;
  153. }
  154. }
  155. int main(int argc, char** argv)
  156. {
  157. glutInit(&argc, argv);
  158. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
  159. glutInitWindowSize (350, 350);
  160. glutInitWindowPosition (100, 100);
  161. glutCreateWindow (argv[0]);
  162. init ();
  163. glutDisplayFunc(display);
  164. glutReshapeFunc(reshape);
  165. glutMouseFunc(mouse);
  166. glutKeyboardFunc (keyboard);
  167. glutMainLoop();
  168. return 0;
  169. }
  170. #else
  171. int main(int argc, char** argv)
  172. {
  173. fprintf (stderr, "This program demonstrates a feature which is not in OpenGL Version 1.0.\n");
  174. fprintf (stderr, "If your implementation of OpenGL Version 1.0 has the right extensions,\n");
  175. fprintf (stderr, "you may be able to modify this program to make it run.\n");
  176. return 0;
  177. }
  178. #endif