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.

checker.c 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Copyright (c) Mark J. Kilgard, 1994. */
  2. /*
  3. * (c) Copyright 1993, Silicon Graphics, Inc.
  4. * ALL RIGHTS RESERVED
  5. * Permission to use, copy, modify, and distribute this software for
  6. * any purpose and without fee is hereby granted, provided that the above
  7. * copyright notice appear in all copies and that both the copyright notice
  8. * and this permission notice appear in supporting documentation, and that
  9. * the name of Silicon Graphics, Inc. not be used in advertising
  10. * or publicity pertaining to distribution of the software without specific,
  11. * written prior permission.
  12. *
  13. * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  14. * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  15. * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  16. * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
  17. * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  18. * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  19. * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  20. * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  21. * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN
  22. * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  23. * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  24. * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  25. *
  26. * US Government Users Restricted Rights
  27. * Use, duplication, or disclosure by the Government is subject to
  28. * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  29. * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  30. * clause at DFARS 252.227-7013 and/or in similar or successor
  31. * clauses in the FAR or the DOD or NASA FAR Supplement.
  32. * Unpublished-- rights reserved under the copyright laws of the
  33. * United States. Contractor/manufacturer is Silicon Graphics,
  34. * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
  35. *
  36. * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  37. */
  38. /* checker.c
  39. * This program texture maps a checkerboard image onto
  40. * two rectangles. This program clamps the texture, if
  41. * the texture coordinates fall outside 0.0 and 1.0.
  42. */
  43. #include <stdlib.h>
  44. #include <GL/glut.h>
  45. /* Create checkerboard texture */
  46. #define checkImageWidth 64
  47. #define checkImageHeight 64
  48. GLubyte checkImage[checkImageWidth][checkImageHeight][3];
  49. void makeCheckImage(void)
  50. {
  51. int i, j, c;
  52. for (i = 0; i < checkImageWidth; i++) {
  53. for (j = 0; j < checkImageHeight; j++) {
  54. c = ((((i&0x8)==0)^((j&0x8)==0)))*255;
  55. checkImage[i][j][0] = (GLubyte) c;
  56. checkImage[i][j][1] = (GLubyte) c;
  57. checkImage[i][j][2] = (GLubyte) c;
  58. }
  59. }
  60. }
  61. void myinit(void)
  62. {
  63. glClearColor (0.0, 0.0, 0.0, 0.0);
  64. glEnable(GL_DEPTH_TEST);
  65. glDepthFunc(GL_LESS);
  66. makeCheckImage();
  67. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  68. glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
  69. checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
  70. &checkImage[0][0][0]);
  71. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  72. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  73. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  74. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  75. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  76. glEnable(GL_TEXTURE_2D);
  77. glShadeModel(GL_FLAT);
  78. }
  79. void display(void)
  80. {
  81. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  82. glBegin(GL_QUADS);
  83. glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
  84. glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
  85. glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
  86. glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
  87. glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0);
  88. glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0);
  89. glTexCoord2f(1.0, 1.0); glVertex3f(2.41421, 1.0, -1.41421);
  90. glTexCoord2f(1.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421);
  91. glEnd();
  92. glutSwapBuffers();
  93. }
  94. void myReshape(int w, int h)
  95. {
  96. glViewport(0, 0, w, h);
  97. glMatrixMode(GL_PROJECTION);
  98. glLoadIdentity();
  99. gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30.0);
  100. glMatrixMode(GL_MODELVIEW);
  101. glLoadIdentity();
  102. glTranslatef(0.0, 0.0, -3.6);
  103. }
  104. static void
  105. key(unsigned char k, int x, int y)
  106. {
  107. switch (k) {
  108. case 27: /* Escape */
  109. exit(0);
  110. break;
  111. default:
  112. return;
  113. }
  114. glutPostRedisplay();
  115. }
  116. int
  117. main(int argc, char** argv)
  118. {
  119. glutInit(&argc, argv);
  120. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  121. glutCreateWindow("checker");
  122. myinit();
  123. glutReshapeFunc (myReshape);
  124. glutDisplayFunc(display);
  125. glutKeyboardFunc(key);
  126. glutMainLoop();
  127. return 0; /* ANSI C requires main to return int. */
  128. }