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.

bug_texstore_i8.c 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software and
  5. * its documentation for any purpose is hereby granted without fee, provided
  6. * that (i) the above copyright notices and this permission notice appear in
  7. * all copies of the software and related documentation, and (ii) the name of
  8. * Silicon Graphics may not be used in any advertising or
  9. * publicity relating to the software without the specific, prior written
  10. * permission of Silicon Graphics.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
  13. * ANY KIND,
  14. * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
  15. * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
  18. * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  19. * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  20. * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
  21. * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  22. * OF THIS SOFTWARE.
  23. */
  24. /*
  25. * Based on the trivial/quad-tex-2d program.
  26. * Modified by Jakob Bornecrantz <jakob@tungstengraphics.com>
  27. */
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include <stdlib.h>
  31. #include <GL/glut.h>
  32. static GLenum Target = GL_TEXTURE_2D;
  33. static GLenum Filter = GL_NEAREST;
  34. GLenum doubleBuffer;
  35. static float Rot = 0;
  36. static int win = 0;
  37. static void Init(void)
  38. {
  39. int internalFormat;
  40. int sourceFormat;
  41. fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  42. fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  43. fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  44. glClearColor(0.0, 0.0, 1.0, 0.0);
  45. #define SIZE 16
  46. {
  47. GLubyte tex2d[SIZE][SIZE][4];
  48. GLint s, t;
  49. for (s = 0; s < SIZE; s++) {
  50. for (t = 0; t < SIZE; t++) {
  51. tex2d[t][s][0] = 0xff;
  52. tex2d[t][s][1] = 0xff;
  53. tex2d[t][s][2] = 0xff;
  54. tex2d[t][s][3] = 0xff;
  55. }
  56. }
  57. internalFormat = GL_LUMINANCE8;
  58. sourceFormat = GL_RGBA;
  59. glTexImage2D(Target,
  60. 0,
  61. internalFormat,
  62. SIZE, SIZE,
  63. 0,
  64. sourceFormat,
  65. GL_UNSIGNED_BYTE,
  66. //GL_UNSIGNED_INT,
  67. tex2d);
  68. glEnable(Target);
  69. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  70. glTexParameterf(Target, GL_TEXTURE_WRAP_R, GL_REPEAT);
  71. glTexParameterf(Target, GL_TEXTURE_MIN_FILTER, Filter);
  72. glTexParameterf(Target, GL_TEXTURE_MAG_FILTER, Filter);
  73. }
  74. }
  75. static void Reshape(int width, int height)
  76. {
  77. glViewport(0, 0, (GLint)width, (GLint)height);
  78. glMatrixMode(GL_PROJECTION);
  79. glLoadIdentity();
  80. #if 0
  81. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  82. #else
  83. glFrustum(-1, 1, -1, 1, 10, 20);
  84. #endif
  85. glMatrixMode(GL_MODELVIEW);
  86. glLoadIdentity();
  87. glTranslatef(0, 0, -15);
  88. }
  89. static void Key(unsigned char key, int x, int y)
  90. {
  91. switch (key) {
  92. case 'r':
  93. Rot += 10.0;
  94. break;
  95. case 'R':
  96. Rot -= 10.0;
  97. break;
  98. case 27:
  99. glutDestroyWindow(win);
  100. exit(0);
  101. default:
  102. return;
  103. }
  104. glutPostRedisplay();
  105. }
  106. static void Draw(void)
  107. {
  108. glClear(GL_COLOR_BUFFER_BIT);
  109. glPushMatrix();
  110. glRotatef(Rot, 0, 1, 0);
  111. glBegin(GL_QUADS);
  112. glTexCoord2f(1,0);
  113. glVertex3f( 0.9, -0.9, 0.0);
  114. glTexCoord2f(1,1);
  115. glVertex3f( 0.9, 0.9, 0.0);
  116. glTexCoord2f(0,1);
  117. glVertex3f(-0.9, 0.9, 0.0);
  118. glTexCoord2f(0,0);
  119. glVertex3f(-0.9, -0.9, 0.0);
  120. glEnd();
  121. glPopMatrix();
  122. glFlush();
  123. if (doubleBuffer) {
  124. glutSwapBuffers();
  125. }
  126. }
  127. static GLenum Args(int argc, char **argv)
  128. {
  129. GLint i;
  130. doubleBuffer = GL_FALSE;
  131. for (i = 1; i < argc; i++) {
  132. if (strcmp(argv[i], "-sb") == 0) {
  133. doubleBuffer = GL_FALSE;
  134. } else if (strcmp(argv[i], "-db") == 0) {
  135. doubleBuffer = GL_TRUE;
  136. } else {
  137. fprintf(stderr, "%s (Bad option).\n", argv[i]);
  138. return GL_FALSE;
  139. }
  140. }
  141. return GL_TRUE;
  142. }
  143. int main(int argc, char **argv)
  144. {
  145. GLenum type;
  146. glutInit(&argc, argv);
  147. if (Args(argc, argv) == GL_FALSE) {
  148. exit(1);
  149. }
  150. glutInitWindowPosition(0, 0);
  151. glutInitWindowSize(250, 250);
  152. type = GLUT_RGB;
  153. type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  154. glutInitDisplayMode(type);
  155. win = glutCreateWindow("Tex test");
  156. if (!win) {
  157. exit(1);
  158. }
  159. Init();
  160. glutReshapeFunc(Reshape);
  161. glutKeyboardFunc(Key);
  162. glutDisplayFunc(Draw);
  163. glutMainLoop();
  164. return 0;
  165. }