Clone of mesa.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. * aapoly.c
  39. * This program draws filled polygons with antialiased
  40. * edges. The special GL_SRC_ALPHA_SATURATE blending
  41. * function is used.
  42. * Pressing the 't' key turns the antialiasing on and off.
  43. */
  44. #include <GL/glut.h>
  45. #include <stdlib.h>
  46. #include <stdio.h>
  47. #include <string.h>
  48. GLboolean polySmooth = GL_TRUE;
  49. static void init(void)
  50. {
  51. glCullFace (GL_BACK);
  52. glEnable (GL_CULL_FACE);
  53. glBlendFunc (GL_SRC_ALPHA_SATURATE, GL_ONE);
  54. glClearColor (0.0, 0.0, 0.0, 0.0);
  55. }
  56. #define NFACE 6
  57. #define NVERT 8
  58. void drawCube(GLdouble x0, GLdouble x1, GLdouble y0, GLdouble y1,
  59. GLdouble z0, GLdouble z1)
  60. {
  61. static GLfloat v[8][3];
  62. static GLfloat c[8][4] = {
  63. {0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 1.0},
  64. {0.0, 1.0, 0.0, 1.0}, {1.0, 1.0, 0.0, 1.0},
  65. {0.0, 0.0, 1.0, 1.0}, {1.0, 0.0, 1.0, 1.0},
  66. {0.0, 1.0, 1.0, 1.0}, {1.0, 1.0, 1.0, 1.0}
  67. };
  68. /* indices of front, top, left, bottom, right, back faces */
  69. static GLubyte indices[NFACE][4] = {
  70. {4, 5, 6, 7}, {2, 3, 7, 6}, {0, 4, 7, 3},
  71. {0, 1, 5, 4}, {1, 5, 6, 2}, {0, 3, 2, 1}
  72. };
  73. v[0][0] = v[3][0] = v[4][0] = v[7][0] = x0;
  74. v[1][0] = v[2][0] = v[5][0] = v[6][0] = x1;
  75. v[0][1] = v[1][1] = v[4][1] = v[5][1] = y0;
  76. v[2][1] = v[3][1] = v[6][1] = v[7][1] = y1;
  77. v[0][2] = v[1][2] = v[2][2] = v[3][2] = z0;
  78. v[4][2] = v[5][2] = v[6][2] = v[7][2] = z1;
  79. #ifdef GL_VERSION_1_1
  80. glEnableClientState (GL_VERTEX_ARRAY);
  81. glEnableClientState (GL_COLOR_ARRAY);
  82. glVertexPointer (3, GL_FLOAT, 0, v);
  83. glColorPointer (4, GL_FLOAT, 0, c);
  84. glDrawElements (GL_QUADS, NFACE*4, GL_UNSIGNED_BYTE, indices);
  85. glDisableClientState (GL_VERTEX_ARRAY);
  86. glDisableClientState (GL_COLOR_ARRAY);
  87. #else
  88. printf ("If this is GL Version 1.0, ");
  89. printf ("vertex arrays are not supported.\n");
  90. exit(1);
  91. #endif
  92. }
  93. /* Note: polygons must be drawn from front to back
  94. * for proper blending.
  95. */
  96. void display(void)
  97. {
  98. if (polySmooth) {
  99. glClear (GL_COLOR_BUFFER_BIT);
  100. glEnable (GL_BLEND);
  101. glEnable (GL_POLYGON_SMOOTH);
  102. glDisable (GL_DEPTH_TEST);
  103. }
  104. else {
  105. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  106. glDisable (GL_BLEND);
  107. glDisable (GL_POLYGON_SMOOTH);
  108. glEnable (GL_DEPTH_TEST);
  109. }
  110. glPushMatrix ();
  111. glTranslatef (0.0, 0.0, -8.0);
  112. glRotatef (30.0, 1.0, 0.0, 0.0);
  113. glRotatef (60.0, 0.0, 1.0, 0.0);
  114. drawCube(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5);
  115. glPopMatrix ();
  116. glFlush ();
  117. }
  118. void reshape(int w, int h)
  119. {
  120. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  121. glMatrixMode(GL_PROJECTION);
  122. glLoadIdentity();
  123. gluPerspective(30.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
  124. glMatrixMode(GL_MODELVIEW);
  125. glLoadIdentity();
  126. }
  127. /* ARGSUSED1 */
  128. void keyboard(unsigned char key, int x, int y)
  129. {
  130. switch (key) {
  131. case 't':
  132. case 'T':
  133. polySmooth = !polySmooth;
  134. glutPostRedisplay();
  135. break;
  136. case 27:
  137. exit(0); /* Escape key */
  138. break;
  139. default:
  140. break;
  141. }
  142. }
  143. /* Main Loop
  144. */
  145. int main(int argc, char** argv)
  146. {
  147. glutInit(&argc, argv);
  148. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB
  149. | GLUT_ALPHA | GLUT_DEPTH);
  150. glutInitWindowSize(200, 200);
  151. glutCreateWindow(argv[0]);
  152. init ();
  153. glutReshapeFunc (reshape);
  154. glutKeyboardFunc (keyboard);
  155. glutDisplayFunc (display);
  156. glutMainLoop();
  157. return 0;
  158. }