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.

mipgen.c 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /* Test GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL
  2. * Brian Paul
  3. * 10 May 2006
  4. */
  5. /* Copyright (c) Mark J. Kilgard, 1994. */
  6. /*
  7. * (c) Copyright 1993, Silicon Graphics, Inc.
  8. * ALL RIGHTS RESERVED
  9. * Permission to use, copy, modify, and distribute this software for
  10. * any purpose and without fee is hereby granted, provided that the above
  11. * copyright notice appear in all copies and that both the copyright notice
  12. * and this permission notice appear in supporting documentation, and that
  13. * the name of Silicon Graphics, Inc. not be used in advertising
  14. * or publicity pertaining to distribution of the software without specific,
  15. * written prior permission.
  16. *
  17. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  18. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  19. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  20. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  21. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  22. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  23. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  24. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  25. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  26. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  27. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  28. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  29. *
  30. * US Government Users Restricted Rights
  31. * Use, duplication, or disclosure by the Government is subject to
  32. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  33. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  34. * clause at DFARS 252.227-7013 and/or in similar or successor
  35. * clauses in the FAR or the DOD or NASA FAR Supplement.
  36. * Unpublished-- rights reserved under the copyright laws of the
  37. * United States. Contractor/manufacturer is Silicon Graphics,
  38. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  39. *
  40. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  41. */
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #include <GL/glew.h>
  45. #include <GL/glut.h>
  46. #include "readtex.h"
  47. static GLfloat LodBias = 6.0; /* make smallest miplevel visible */
  48. static GLuint texImage;
  49. #define WIDTH 2
  50. #define HEIGHT 2
  51. static void
  52. InitValues(void)
  53. {
  54. LodBias = 6.0; /* make smallest miplevel visible */
  55. }
  56. static void MakeImage(void)
  57. {
  58. const GLubyte color0[4] = { 0xff, 0x80, 0x20, 0xff };
  59. const GLubyte color1[4] = { 0x10, 0x20, 0x40, 0xff };
  60. GLubyte img[WIDTH*HEIGHT*3];
  61. int i, j;
  62. for (i = 0; i < HEIGHT; i++) {
  63. for (j = 0; j < WIDTH; j++) {
  64. int k = (i * WIDTH + j) * 3;
  65. int p = ((i+j)%2);
  66. if (p == 0) {
  67. img[k + 0] = color0[0];
  68. img[k + 1] = color0[1];
  69. img[k + 2] = color0[2];
  70. }
  71. else {
  72. img[k + 0] = color1[0];
  73. img[k + 1] = color1[1];
  74. img[k + 2] = color1[2];
  75. }
  76. }
  77. }
  78. glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
  79. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0,
  80. GL_RGB, GL_UNSIGNED_BYTE, img);
  81. glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_FALSE);
  82. }
  83. static void myinit(void)
  84. {
  85. InitValues();
  86. glShadeModel(GL_FLAT);
  87. glTranslatef(0.0, 0.0, -3.6);
  88. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  89. glGenTextures(1, &texImage);
  90. glBindTexture(GL_TEXTURE_2D, texImage);
  91. MakeImage();
  92. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  93. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  94. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  95. glEnable(GL_TEXTURE_2D);
  96. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
  97. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
  98. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -1);
  99. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1);
  100. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  101. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  102. GL_NEAREST_MIPMAP_NEAREST);
  103. }
  104. static void display(void)
  105. {
  106. GLfloat tcm = 1.0;
  107. glBindTexture(GL_TEXTURE_2D, texImage);
  108. printf("Bias=%.2g\n", LodBias);
  109. fflush(stdout);
  110. glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias);
  111. glClear(GL_COLOR_BUFFER_BIT);
  112. glBegin(GL_QUADS);
  113. glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
  114. glTexCoord2f(0.0, tcm); glVertex3f(-2.0, 1.0, 0.0);
  115. glTexCoord2f(tcm * 3000.0, tcm); glVertex3f(3000.0, 1.0, -6000.0);
  116. glTexCoord2f(tcm * 3000.0, 0.0); glVertex3f(3000.0, -1.0, -6000.0);
  117. glEnd();
  118. glFlush();
  119. }
  120. static void myReshape(int w, int h)
  121. {
  122. glViewport(0, 0, w, h);
  123. glMatrixMode(GL_PROJECTION);
  124. glLoadIdentity();
  125. gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0);
  126. glMatrixMode(GL_MODELVIEW);
  127. glLoadIdentity();
  128. }
  129. static void
  130. key(unsigned char k, int x, int y)
  131. {
  132. (void) x;
  133. (void) y;
  134. switch (k) {
  135. case 'l':
  136. LodBias -= 0.25;
  137. break;
  138. case 'L':
  139. LodBias += 0.25;
  140. break;
  141. case ' ':
  142. InitValues();
  143. break;
  144. case 27: /* Escape */
  145. exit(0);
  146. break;
  147. default:
  148. return;
  149. }
  150. glutPostRedisplay();
  151. }
  152. static void usage(void)
  153. {
  154. printf("usage:\n");
  155. printf(" l/L decrease/increase GL_TEXTURE_LOD_BIAS\n");
  156. printf(" SPACE reset values\n");
  157. }
  158. int main(int argc, char** argv)
  159. {
  160. glutInit(&argc, argv);
  161. glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB );
  162. glutInitWindowSize (600, 600);
  163. glutCreateWindow (argv[0]);
  164. glewInit();
  165. myinit();
  166. glutReshapeFunc (myReshape);
  167. glutDisplayFunc(display);
  168. glutKeyboardFunc(key);
  169. usage();
  170. glutMainLoop();
  171. return 0; /* ANSI C requires main to return int. */
  172. }