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.

mipmap.c 5.7KB

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