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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. /* mipmap.c
  39. * This program demonstrates using mipmaps for texture maps.
  40. * To overtly show the effect of mipmaps, each mipmap reduction
  41. * level has a solidly colored, contrasting texture image.
  42. * Thus, the quadrilateral which is drawn is drawn with several
  43. * different colors.
  44. */
  45. #include <stdlib.h>
  46. #include <stdio.h>
  47. #include <GL/glut.h>
  48. GLubyte mipmapImage32[40][46][3];
  49. GLubyte mipmapImage16[20][23][3];
  50. GLubyte mipmapImage8[10][11][3];
  51. GLubyte mipmapImage4[5][5][3];
  52. GLubyte mipmapImage2[2][2][3];
  53. GLubyte mipmapImage1[1][1][3];
  54. static void makeImages(void)
  55. {
  56. int i, j;
  57. for (i = 0; i < 40; i++) {
  58. for (j = 0; j < 46; j++) {
  59. mipmapImage32[i][j][0] = 255;
  60. mipmapImage32[i][j][1] = 255;
  61. mipmapImage32[i][j][2] = 0;
  62. }
  63. }
  64. for (i = 0; i < 20; i++) {
  65. for (j = 0; j < 23; j++) {
  66. mipmapImage16[i][j][0] = 255;
  67. mipmapImage16[i][j][1] = 0;
  68. mipmapImage16[i][j][2] = 255;
  69. }
  70. }
  71. for (i = 0; i < 10; i++) {
  72. for (j = 0; j < 11; j++) {
  73. mipmapImage8[i][j][0] = 255;
  74. mipmapImage8[i][j][1] = 0;
  75. mipmapImage8[i][j][2] = 0;
  76. }
  77. }
  78. for (i = 0; i < 5; i++) {
  79. for (j = 0; j < 5; j++) {
  80. mipmapImage4[i][j][0] = 0;
  81. mipmapImage4[i][j][1] = 255;
  82. mipmapImage4[i][j][2] = 0;
  83. }
  84. }
  85. for (i = 0; i < 2; i++) {
  86. for (j = 0; j < 2; j++) {
  87. mipmapImage2[i][j][0] = 0;
  88. mipmapImage2[i][j][1] = 0;
  89. mipmapImage2[i][j][2] = 255;
  90. }
  91. }
  92. mipmapImage1[0][0][0] = 255;
  93. mipmapImage1[0][0][1] = 255;
  94. mipmapImage1[0][0][2] = 255;
  95. }
  96. static void myinit(void)
  97. {
  98. if (!glutExtensionSupported("GL_ARB_texture_non_power_of_two")) {
  99. printf("Sorry, this program requires GL_ARB_texture_non_power_of_two\n");
  100. exit(1);
  101. }
  102. glEnable(GL_DEPTH_TEST);
  103. glDepthFunc(GL_LESS);
  104. glShadeModel(GL_FLAT);
  105. glTranslatef(0.0, 0.0, -3.6);
  106. makeImages();
  107. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  108. glTexImage2D(GL_TEXTURE_2D, 0, 3, 40, 46, 0,
  109. GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage32[0][0][0]);
  110. glTexImage2D(GL_TEXTURE_2D, 1, 3, 20, 23, 0,
  111. GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage16[0][0][0]);
  112. glTexImage2D(GL_TEXTURE_2D, 2, 3, 10, 11, 0,
  113. GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage8[0][0][0]);
  114. glTexImage2D(GL_TEXTURE_2D, 3, 3, 5, 5, 0,
  115. GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage4[0][0][0]);
  116. glTexImage2D(GL_TEXTURE_2D, 4, 3, 2, 2, 0,
  117. GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage2[0][0][0]);
  118. glTexImage2D(GL_TEXTURE_2D, 5, 3, 1, 1, 0,
  119. GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage1[0][0][0]);
  120. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  121. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  122. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  123. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  124. GL_NEAREST_MIPMAP_NEAREST);
  125. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  126. glEnable(GL_TEXTURE_2D);
  127. }
  128. static void display(void)
  129. {
  130. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  131. glBegin(GL_QUADS);
  132. glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
  133. glTexCoord2f(0.0, 8.0); glVertex3f(-2.0, 1.0, 0.0);
  134. glTexCoord2f(8.0, 8.0); glVertex3f(2000.0, 1.0, -6000.0);
  135. glTexCoord2f(8.0, 0.0); glVertex3f(2000.0, -1.0, -6000.0);
  136. glEnd();
  137. glFlush();
  138. }
  139. static void myReshape(int w, int h)
  140. {
  141. glViewport(0, 0, w, h);
  142. glMatrixMode(GL_PROJECTION);
  143. glLoadIdentity();
  144. gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0);
  145. glMatrixMode(GL_MODELVIEW);
  146. glLoadIdentity();
  147. }
  148. static void
  149. key(unsigned char k, int x, int y)
  150. {
  151. switch (k) {
  152. case 27: /* Escape */
  153. exit(0);
  154. break;
  155. default:
  156. return;
  157. }
  158. glutPostRedisplay();
  159. }
  160. int main(int argc, char** argv)
  161. {
  162. glutInit(&argc, argv);
  163. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  164. glutInitWindowSize (500, 500);
  165. glutCreateWindow (argv[0]);
  166. myinit();
  167. glutReshapeFunc (myReshape);
  168. glutDisplayFunc(display);
  169. glutKeyboardFunc(key);
  170. glutMainLoop();
  171. return 0; /* ANSI C requires main to return int. */
  172. }