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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 <GL/glut.h>
  44. /* Create checkerboard texture */
  45. #define checkImageWidth 64
  46. #define checkImageHeight 64
  47. GLubyte checkImage[checkImageWidth][checkImageHeight][3];
  48. void makeCheckImage(void)
  49. {
  50. int i, j, c;
  51. for (i = 0; i < checkImageWidth; i++) {
  52. for (j = 0; j < checkImageHeight; j++) {
  53. c = ((((i&0x8)==0)^((j&0x8)==0)))*255;
  54. checkImage[i][j][0] = (GLubyte) c;
  55. checkImage[i][j][1] = (GLubyte) c;
  56. checkImage[i][j][2] = (GLubyte) c;
  57. }
  58. }
  59. }
  60. void myinit(void)
  61. {
  62. glClearColor (0.0, 0.0, 0.0, 0.0);
  63. glEnable(GL_DEPTH_TEST);
  64. glDepthFunc(GL_LESS);
  65. makeCheckImage();
  66. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  67. glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
  68. checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
  69. &checkImage[0][0][0]);
  70. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  71. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  72. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  73. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  74. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
  75. glEnable(GL_TEXTURE_2D);
  76. glShadeModel(GL_FLAT);
  77. }
  78. void display(void)
  79. {
  80. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  81. glBegin(GL_QUADS);
  82. glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
  83. glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
  84. glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
  85. glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);
  86. glTexCoord2f(0.0, 0.0); glVertex3f(1.0, -1.0, 0.0);
  87. glTexCoord2f(0.0, 1.0); glVertex3f(1.0, 1.0, 0.0);
  88. glTexCoord2f(1.0, 1.0); glVertex3f(2.41421, 1.0, -1.41421);
  89. glTexCoord2f(1.0, 0.0); glVertex3f(2.41421, -1.0, -1.41421);
  90. glEnd();
  91. glutSwapBuffers();
  92. }
  93. void myReshape(int w, int h)
  94. {
  95. glViewport(0, 0, w, h);
  96. glMatrixMode(GL_PROJECTION);
  97. glLoadIdentity();
  98. gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30.0);
  99. glMatrixMode(GL_MODELVIEW);
  100. glLoadIdentity();
  101. glTranslatef(0.0, 0.0, -3.6);
  102. }
  103. static void
  104. key(unsigned char k, int x, int y)
  105. {
  106. switch (k) {
  107. case 27: /* Escape */
  108. exit(0);
  109. break;
  110. default:
  111. return;
  112. }
  113. glutPostRedisplay();
  114. }
  115. int
  116. main(int argc, char** argv)
  117. {
  118. glutInit(&argc, argv);
  119. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
  120. glutCreateWindow("checker");
  121. myinit();
  122. glutReshapeFunc (myReshape);
  123. glutDisplayFunc(display);
  124. glutKeyboardFunc(key);
  125. glutMainLoop();
  126. return 0; /* ANSI C requires main to return int. */
  127. }