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.

arbnpot-mipmap.c 6.0KB

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