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.

texwrap.c 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /* $Id: texwrap.c,v 1.1 2001/03/26 19:45:57 brianp Exp $ */
  2. /*
  3. * Test texture wrap modes.
  4. *
  5. * Brian Paul March 2001
  6. */
  7. #define GL_GLEXT_PROTOTYPES
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <math.h>
  11. #include <GL/glut.h>
  12. #ifndef GL_CLAMP_TO_BORDER_ARB
  13. #define GL_CLAMP_TO_BORDER_ARB 0x812D
  14. #endif
  15. #define SIZE 4
  16. static GLubyte TexImage[SIZE+2][SIZE+2][4];
  17. static void
  18. PrintString(const char *s)
  19. {
  20. while (*s) {
  21. glutBitmapCharacter(GLUT_BITMAP_8_BY_13, (int) *s);
  22. s++;
  23. }
  24. }
  25. static void Display( void )
  26. {
  27. static const GLenum modes[] = {
  28. GL_REPEAT,
  29. GL_CLAMP,
  30. GL_CLAMP_TO_EDGE,
  31. GL_CLAMP_TO_BORDER_ARB
  32. };
  33. static const char *names[] = {
  34. "GL_REPEAT",
  35. "GL_CLAMP",
  36. "GL_CLAMP_TO_EDGE",
  37. "GL_CLAMP_TO_BORDER_ARB"
  38. };
  39. GLint i, j;
  40. GLint numModes;
  41. numModes = glutExtensionSupported("GL_ARB_texture_border_clamp") ? 4 : 3;
  42. glClearColor(0.5, 0.5, 0.5, 1.0);
  43. glClear( GL_COLOR_BUFFER_BIT );
  44. #if 0
  45. /* draw texture as image */
  46. glDisable(GL_TEXTURE_2D);
  47. glWindowPos2iMESA(1, 1);
  48. glDrawPixels(6, 6, GL_RGBA, GL_UNSIGNED_BYTE, (void *) TexImage);
  49. #endif
  50. glEnable(GL_TEXTURE_2D);
  51. /* loop over min/mag filters */
  52. for (i = 0; i < 2; i++) {
  53. if (i) {
  54. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  55. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  56. }
  57. else {
  58. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  59. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  60. }
  61. /* loop over border modes */
  62. for (j = 0; j < numModes; j++) {
  63. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, modes[j]);
  64. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, modes[j]);
  65. glPushMatrix();
  66. glTranslatef(j * 150 + 10, i * 150 + 25, 0);
  67. glBegin(GL_POLYGON);
  68. glTexCoord2f(-0.2, -0.2); glVertex2f( 0, 0);
  69. glTexCoord2f( 1.2, -0.2); glVertex2f(140, 0);
  70. glTexCoord2f( 1.2, 1.2); glVertex2f(140, 140);
  71. glTexCoord2f(-0.2, 1.2); glVertex2f( 0, 140);
  72. glEnd();
  73. glPopMatrix();
  74. }
  75. }
  76. glDisable(GL_TEXTURE_2D);
  77. for (i = 0; i < numModes; i++) {
  78. glWindowPos2iMESA( i * 150 + 10, 5);
  79. PrintString(names[i]);
  80. }
  81. glutSwapBuffers();
  82. }
  83. static void Reshape( int width, int height )
  84. {
  85. glViewport( 0, 0, width, height );
  86. glMatrixMode( GL_PROJECTION );
  87. glLoadIdentity();
  88. glOrtho(0, width, 0, height, -1, 1);
  89. glMatrixMode( GL_MODELVIEW );
  90. glLoadIdentity();
  91. }
  92. static void Key( unsigned char key, int x, int y )
  93. {
  94. (void) x;
  95. (void) y;
  96. switch (key) {
  97. case 27:
  98. exit(0);
  99. break;
  100. }
  101. glutPostRedisplay();
  102. }
  103. static void Init( void )
  104. {
  105. static const GLubyte border[4] = { 0, 255, 0, 255 };
  106. GLint i, j;
  107. for (i = 0; i < SIZE+2; i++) {
  108. for (j = 0; j < SIZE+2; j++) {
  109. if (i == 0 || j == 0 || i == SIZE+1 || j == SIZE+1) {
  110. /* border color */
  111. TexImage[i][j][0] = border[0];
  112. TexImage[i][j][1] = border[1];
  113. TexImage[i][j][2] = border[2];
  114. TexImage[i][j][3] = border[3];
  115. }
  116. else if ((i + j) & 1) {
  117. /* white */
  118. TexImage[i][j][0] = 255;
  119. TexImage[i][j][1] = 255;
  120. TexImage[i][j][2] = 255;
  121. TexImage[i][j][3] = 255;
  122. }
  123. else {
  124. /* black */
  125. TexImage[i][j][0] = 0;
  126. TexImage[i][j][1] = 0;
  127. TexImage[i][j][2] = 0;
  128. TexImage[i][j][3] = 0;
  129. }
  130. }
  131. }
  132. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, SIZE+2, SIZE+2, 1,
  133. GL_RGBA, GL_UNSIGNED_BYTE, (void *) TexImage);
  134. }
  135. int main( int argc, char *argv[] )
  136. {
  137. glutInit( &argc, argv );
  138. glutInitWindowPosition( 0, 0 );
  139. glutInitWindowSize( 650, 340 );
  140. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
  141. glutCreateWindow(argv[0]);
  142. glutReshapeFunc( Reshape );
  143. glutKeyboardFunc( Key );
  144. glutDisplayFunc( Display );
  145. Init();
  146. glutMainLoop();
  147. return 0;
  148. }