Clone of mesa.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

texbind.c 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (c) 1993-1997, Silicon Graphics, Inc.
  3. * ALL RIGHTS RESERVED
  4. * Permission to use, copy, modify, and distribute this software for
  5. * any purpose and without fee is hereby granted, provided that the above
  6. * copyright notice appear in all copies and that both the copyright notice
  7. * and this permission notice appear in supporting documentation, and that
  8. * the name of Silicon Graphics, Inc. not be used in advertising
  9. * or publicity pertaining to distribution of the software without specific,
  10. * written prior permission.
  11. *
  12. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  16. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  21. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24. *
  25. * US Government Users Restricted Rights
  26. * Use, duplication, or disclosure by the Government is subject to
  27. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29. * clause at DFARS 252.227-7013 and/or in similar or successor
  30. * clauses in the FAR or the DOD or NASA FAR Supplement.
  31. * Unpublished-- rights reserved under the copyright laws of the
  32. * United States. Contractor/manufacturer is Silicon Graphics,
  33. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  34. *
  35. * OpenGL(R) is a registered trademark of Silicon Graphics, Inc.
  36. */
  37. /* texbind.c
  38. * This program demonstrates using glBindTexture() by
  39. * creating and managing two textures.
  40. */
  41. #include <GL/glut.h>
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #ifdef GL_VERSION_1_1
  45. /* Create checkerboard texture */
  46. #define checkImageWidth 64
  47. #define checkImageHeight 64
  48. static GLubyte checkImage[checkImageHeight][checkImageWidth][4];
  49. static GLubyte otherImage[checkImageHeight][checkImageWidth][4];
  50. static GLuint texName[2];
  51. void makeCheckImages(void)
  52. {
  53. int i, j, c;
  54. for (i = 0; i < checkImageHeight; i++) {
  55. for (j = 0; j < checkImageWidth; j++) {
  56. c = ((((i&0x8)==0)^((j&0x8)==0)))*255;
  57. checkImage[i][j][0] = (GLubyte) c;
  58. checkImage[i][j][1] = (GLubyte) c;
  59. checkImage[i][j][2] = (GLubyte) c;
  60. checkImage[i][j][3] = (GLubyte) 255;
  61. c = ((((i&0x10)==0)^((j&0x10)==0)))*255;
  62. otherImage[i][j][0] = (GLubyte) c;
  63. otherImage[i][j][1] = (GLubyte) 0;
  64. otherImage[i][j][2] = (GLubyte) 0;
  65. otherImage[i][j][3] = (GLubyte) 255;
  66. }
  67. }
  68. }
  69. void init(void)
  70. {
  71. glClearColor (0.0, 0.0, 0.0, 0.0);
  72. glShadeModel(GL_FLAT);
  73. glEnable(GL_DEPTH_TEST);
  74. makeCheckImages();
  75. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  76. glGenTextures(2, texName);
  77. glBindTexture(GL_TEXTURE_2D, texName[0]);
  78. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  79. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  80. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
  81. GL_NEAREST);
  82. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
  83. GL_NEAREST);
  84. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,
  85. checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
  86. checkImage);
  87. glBindTexture(GL_TEXTURE_2D, texName[1]);
  88. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  89. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  90. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  91. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  92. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  93. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth,
  94. checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
  95. otherImage);
  96. glEnable(GL_TEXTURE_2D);
  97. }
  98. void display(void)
  99. {
  100. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  101. glBindTexture(GL_TEXTURE_2D, texName[0]);
  102. glBegin(GL_QUADS);
  103. glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
  104. glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
  105. glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
  106. glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
  107. glEnd();
  108. glBindTexture(GL_TEXTURE_2D, texName[1]);
  109. glBegin(GL_QUADS);
  110. glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0);
  111. glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0);
  112. glTexCoord2f(1.0, 1.0); glVertex3f(2.41421, 1.0, -1.41421);
  113. glTexCoord2f(1.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421);
  114. glEnd();
  115. glFlush();
  116. }
  117. void reshape(int w, int h)
  118. {
  119. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  120. glMatrixMode(GL_PROJECTION);
  121. glLoadIdentity();
  122. gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);
  123. glMatrixMode(GL_MODELVIEW);
  124. glLoadIdentity();
  125. glTranslatef(0.0, 0.0, -3.6);
  126. }
  127. /* ARGSUSED1 */
  128. void keyboard(unsigned char key, int x, int y)
  129. {
  130. switch (key) {
  131. case 27:
  132. exit(0);
  133. break;
  134. }
  135. }
  136. int main(int argc, char** argv)
  137. {
  138. glutInit(&argc, argv);
  139. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
  140. glutInitWindowSize(250, 250);
  141. glutInitWindowPosition(100, 100);
  142. glutCreateWindow(argv[0]);
  143. init();
  144. glutReshapeFunc(reshape);
  145. glutDisplayFunc(display);
  146. glutKeyboardFunc (keyboard);
  147. glutMainLoop();
  148. return 0;
  149. }
  150. #else
  151. int main(int argc, char** argv)
  152. {
  153. fprintf (stderr, "This program demonstrates a feature which is not in OpenGL Version 1.0.\n");
  154. fprintf (stderr, "If your implementation of OpenGL Version 1.0 has the right extensions,\n");
  155. fprintf (stderr, "you may be able to modify this program to make it run.\n");
  156. return 0;
  157. }
  158. #endif