Clone of mesa.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

arbnpot.c 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Test NPOT textures with the GL_ARB_texture_non_power_of_two extension.
  3. * Brian Paul
  4. * 2 July 2003
  5. */
  6. #include <assert.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <math.h>
  10. #include <GL/glew.h>
  11. #include <GL/glut.h>
  12. #include "../util/readtex.c"
  13. #define IMAGE_FILE "../images/girl.rgb"
  14. static GLfloat Zrot = 0;
  15. static void Display( void )
  16. {
  17. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  18. glPushMatrix();
  19. glRotatef(Zrot, 0, 0, 1);
  20. glBegin(GL_POLYGON);
  21. glTexCoord2f(0, 0);
  22. glVertex2f(-1, -1);
  23. glTexCoord2f(1, 0);
  24. glVertex2f(1, -1);
  25. glTexCoord2f(1, 1);
  26. glVertex2f(1, 1);
  27. glTexCoord2f(0, 1);
  28. glVertex2f(-1, 1);
  29. glEnd();
  30. glPopMatrix();
  31. glutSwapBuffers();
  32. }
  33. static void Reshape( int width, int height )
  34. {
  35. glViewport( 0, 0, width, height );
  36. glMatrixMode( GL_PROJECTION );
  37. glLoadIdentity();
  38. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  39. glMatrixMode( GL_MODELVIEW );
  40. glLoadIdentity();
  41. glTranslatef( 0.0, 0.0, -7.0 );
  42. }
  43. static void Key( unsigned char key, int x, int y )
  44. {
  45. (void) x;
  46. (void) y;
  47. switch (key) {
  48. case 'z':
  49. Zrot -= 1.0;
  50. break;
  51. case 'Z':
  52. Zrot += 1.0;
  53. break;
  54. case 27:
  55. exit(0);
  56. break;
  57. }
  58. glutPostRedisplay();
  59. }
  60. static void Init( void )
  61. {
  62. GLubyte *image;
  63. int imgWidth, imgHeight, minDim, w;
  64. GLenum imgFormat;
  65. if (!glutExtensionSupported("GL_ARB_texture_non_power_of_two")) {
  66. printf("Sorry, this program requires GL_ARB_texture_non_power_of_two\n");
  67. exit(1);
  68. }
  69. #if 1
  70. image = LoadRGBImage( IMAGE_FILE, &imgWidth, &imgHeight, &imgFormat );
  71. if (!image) {
  72. printf("Couldn't read %s\n", IMAGE_FILE);
  73. exit(0);
  74. }
  75. #else
  76. int i, j;
  77. imgFormat = GL_RGB;
  78. imgWidth = 3;
  79. imgHeight = 3;
  80. image = malloc(imgWidth * imgHeight * 3);
  81. for (i = 0; i < imgHeight; i++) {
  82. for (j = 0; j < imgWidth; j++) {
  83. int k = (i * imgWidth + j) * 3;
  84. if ((i + j) & 1) {
  85. image[k+0] = 255;
  86. image[k+1] = 0;
  87. image[k+2] = 0;
  88. }
  89. else {
  90. image[k+0] = 0;
  91. image[k+1] = 255;
  92. image[k+2] = 0;
  93. }
  94. }
  95. }
  96. #endif
  97. printf("Read %d x %d\n", imgWidth, imgHeight);
  98. minDim = imgWidth < imgHeight ? imgWidth : imgHeight;
  99. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  100. /*
  101. * 1D Texture. Test proxy first, if that works, test non-proxy target.
  102. */
  103. glTexImage1D(GL_PROXY_TEXTURE_1D, 0, GL_RGB, imgWidth, 0,
  104. imgFormat, GL_UNSIGNED_BYTE, image);
  105. glGetTexLevelParameteriv(GL_PROXY_TEXTURE_1D, 0, GL_TEXTURE_WIDTH, &w);
  106. assert(w == imgWidth || w == 0);
  107. if (w) {
  108. glTexImage1D(GL_TEXTURE_1D, 0, GL_RGB, imgWidth, 0,
  109. imgFormat, GL_UNSIGNED_BYTE, image);
  110. assert(glGetError() == GL_NO_ERROR);
  111. }
  112. /*
  113. * 2D Texture
  114. */
  115. glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGB, imgWidth, imgHeight, 0,
  116. imgFormat, GL_UNSIGNED_BYTE, image);
  117. glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &w);
  118. assert(w == imgWidth || w == 0);
  119. if (w) {
  120. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, imgWidth, imgHeight, 0,
  121. imgFormat, GL_UNSIGNED_BYTE, image);
  122. assert(glGetError() == GL_NO_ERROR);
  123. }
  124. /*
  125. * 3D Texture
  126. */
  127. glTexImage3D(GL_PROXY_TEXTURE_3D, 0, GL_RGB, imgWidth, imgHeight, 1, 0,
  128. imgFormat, GL_UNSIGNED_BYTE, image);
  129. glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &w);
  130. assert(w == imgWidth || w == 0);
  131. if (w) {
  132. glTexImage3D(GL_TEXTURE_3D, 0, GL_RGB, imgWidth, imgHeight, 1, 0,
  133. imgFormat, GL_UNSIGNED_BYTE, image);
  134. assert(glGetError() == GL_NO_ERROR);
  135. }
  136. /*
  137. * Cube Texture
  138. */
  139. glTexImage2D(GL_PROXY_TEXTURE_CUBE_MAP, 0, GL_RGB,
  140. minDim, minDim, 0,
  141. imgFormat, GL_UNSIGNED_BYTE, image);
  142. glGetTexLevelParameteriv(GL_PROXY_TEXTURE_CUBE_MAP, 0, GL_TEXTURE_WIDTH, &w);
  143. assert(w == minDim || w == 0);
  144. if (w) {
  145. glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGB,
  146. minDim, minDim, 0,
  147. imgFormat, GL_UNSIGNED_BYTE, image);
  148. assert(glGetError() == GL_NO_ERROR);
  149. }
  150. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  151. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  152. glEnable(GL_TEXTURE_2D);
  153. }
  154. int main( int argc, char *argv[] )
  155. {
  156. glutInit( &argc, argv );
  157. glutInitWindowPosition( 0, 0 );
  158. glutInitWindowSize( 400, 400 );
  159. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  160. glutCreateWindow(argv[0]);
  161. glewInit();
  162. glutReshapeFunc( Reshape );
  163. glutKeyboardFunc( Key );
  164. glutDisplayFunc( Display );
  165. Init();
  166. glutMainLoop();
  167. return 0;
  168. }