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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. /* image.c
  38. * This program demonstrates drawing pixels and shows the effect
  39. * of glDrawPixels(), glCopyPixels(), and glPixelZoom().
  40. * Interaction: moving the mouse while pressing the mouse button
  41. * will copy the image in the lower-left corner of the window
  42. * to the mouse position, using the current pixel zoom factors.
  43. * There is no attempt to prevent you from drawing over the original
  44. * image. If you press the 'r' key, the original image and zoom
  45. * factors are reset. If you press the 'z' or 'Z' keys, you change
  46. * the zoom factors.
  47. */
  48. #include <GL/glut.h>
  49. #include <stdlib.h>
  50. #include <stdio.h>
  51. /* Create checkerboard image */
  52. #define checkImageWidth 64
  53. #define checkImageHeight 64
  54. GLubyte checkImage[checkImageHeight][checkImageWidth][3];
  55. static GLdouble zoomFactor = 1.0;
  56. static GLint height;
  57. void makeCheckImage(void)
  58. {
  59. int i, j, c;
  60. for (i = 0; i < checkImageHeight; i++) {
  61. for (j = 0; j < checkImageWidth; j++) {
  62. c = (((i&0x8)==0)^((j&0x8)==0))*255;
  63. checkImage[i][j][0] = (GLubyte) c;
  64. checkImage[i][j][1] = (GLubyte) c;
  65. checkImage[i][j][2] = (GLubyte) c;
  66. }
  67. }
  68. }
  69. void init(void)
  70. {
  71. glClearColor (0.0, 0.0, 0.0, 0.0);
  72. glShadeModel(GL_FLAT);
  73. makeCheckImage();
  74. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  75. }
  76. void display(void)
  77. {
  78. glClear(GL_COLOR_BUFFER_BIT);
  79. glRasterPos2i(0, 0);
  80. glDrawPixels(checkImageWidth, checkImageHeight, GL_RGB,
  81. GL_UNSIGNED_BYTE, checkImage);
  82. glFlush();
  83. }
  84. void reshape(int w, int h)
  85. {
  86. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  87. height = (GLint) h;
  88. glMatrixMode(GL_PROJECTION);
  89. glLoadIdentity();
  90. gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h);
  91. glMatrixMode(GL_MODELVIEW);
  92. glLoadIdentity();
  93. }
  94. void motion(int x, int y)
  95. {
  96. static GLint screeny;
  97. screeny = height - (GLint) y;
  98. glRasterPos2i (x, screeny);
  99. glPixelZoom (zoomFactor, zoomFactor);
  100. glCopyPixels (0, 0, checkImageWidth, checkImageHeight, GL_COLOR);
  101. glPixelZoom (1.0, 1.0);
  102. glFlush ();
  103. }
  104. /* ARGSUSED1 */
  105. void keyboard(unsigned char key, int x, int y)
  106. {
  107. switch (key) {
  108. case 'r':
  109. case 'R':
  110. zoomFactor = 1.0;
  111. glutPostRedisplay();
  112. printf ("zoomFactor reset to 1.0\n");
  113. break;
  114. case 'z':
  115. zoomFactor += 0.5;
  116. if (zoomFactor >= 3.0)
  117. zoomFactor = 3.0;
  118. printf ("zoomFactor is now %4.1f\n", zoomFactor);
  119. break;
  120. case 'Z':
  121. zoomFactor -= 0.5;
  122. if (zoomFactor <= 0.5)
  123. zoomFactor = 0.5;
  124. printf ("zoomFactor is now %4.1f\n", zoomFactor);
  125. break;
  126. case 27:
  127. exit(0);
  128. break;
  129. default:
  130. break;
  131. }
  132. }
  133. int main(int argc, char** argv)
  134. {
  135. glutInit(&argc, argv);
  136. glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
  137. glutInitWindowSize(250, 250);
  138. glutInitWindowPosition(100, 100);
  139. glutCreateWindow(argv[0]);
  140. init();
  141. glutDisplayFunc(display);
  142. glutReshapeFunc(reshape);
  143. glutKeyboardFunc(keyboard);
  144. glutMotionFunc(motion);
  145. glutMainLoop();
  146. return 0;
  147. }