Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. #include <stdio.h>
  25. #include <string.h>
  26. #include <stdlib.h>
  27. #include <GL/glut.h>
  28. #include "loadppm.c"
  29. GLenum doubleBuffer;
  30. GLint windW, windH;
  31. char *fileName = 0;
  32. PPMImage *image;
  33. float point[3];
  34. float zoom;
  35. GLint x, y;
  36. static void Init(void)
  37. {
  38. glClearColor(0.0, 0.0, 0.0, 0.0);
  39. x = 0;
  40. y = windH;
  41. zoom = 1.8;
  42. }
  43. static void Reshape(int width, int height)
  44. {
  45. windW = (GLint)width;
  46. windH = (GLint)height;
  47. glViewport(0, 0, windW, windH);
  48. glMatrixMode(GL_PROJECTION);
  49. glLoadIdentity();
  50. gluOrtho2D(0, windW, 0, windH);
  51. glMatrixMode(GL_MODELVIEW);
  52. }
  53. static void Key(unsigned char key, int x, int y)
  54. {
  55. switch (key) {
  56. case 27:
  57. exit(1);
  58. case 'Z':
  59. zoom += 0.2;
  60. break;
  61. case 'z':
  62. zoom -= 0.2;
  63. if (zoom < 0.2) {
  64. zoom = 0.2;
  65. }
  66. break;
  67. default:
  68. return;
  69. }
  70. glutPostRedisplay();
  71. }
  72. static void Mouse(int button, int state, int mouseX, int mouseY)
  73. {
  74. if (state != GLUT_DOWN)
  75. return;
  76. x = (GLint)mouseX;
  77. y = (GLint)mouseY;
  78. glutPostRedisplay();
  79. }
  80. static void Draw(void)
  81. {
  82. glClear(GL_COLOR_BUFFER_BIT);
  83. point[0] = (windW / 2) - (image->sizeX / 2);
  84. point[1] = (windH / 2) - (image->sizeY / 2);
  85. point[2] = 0;
  86. glRasterPos3fv(point);
  87. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  88. glPixelZoom(1.0, 1.0);
  89. glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE,
  90. image->data);
  91. point[0] = (float)x;
  92. point[1] = windH - (float)y;
  93. point[2] = 0.0;
  94. glRasterPos3fv(point);
  95. glPixelZoom(zoom, zoom);
  96. glCopyPixels((windW/2)-(image->sizeX/2),
  97. (windH/2)-(image->sizeY/2),
  98. image->sizeX, image->sizeY, GL_COLOR);
  99. glFlush();
  100. if (doubleBuffer) {
  101. glutSwapBuffers();
  102. }
  103. }
  104. static GLenum Args(int argc, char **argv)
  105. {
  106. GLint i;
  107. doubleBuffer = GL_FALSE;
  108. for (i = 1; i < argc; i++) {
  109. if (strcmp(argv[i], "-sb") == 0) {
  110. doubleBuffer = GL_FALSE;
  111. } else if (strcmp(argv[i], "-db") == 0) {
  112. doubleBuffer = GL_TRUE;
  113. } else if (strcmp(argv[i], "-f") == 0) {
  114. if (i+1 >= argc || argv[i+1][0] == '-') {
  115. printf("-f (No file name).\n");
  116. return GL_FALSE;
  117. } else {
  118. fileName = argv[++i];
  119. }
  120. } else {
  121. printf("%s (Bad option).\n", argv[i]);
  122. return GL_FALSE;
  123. }
  124. }
  125. return GL_TRUE;
  126. }
  127. int main(int argc, char **argv)
  128. {
  129. GLenum type;
  130. glutInit(&argc, argv);
  131. if (Args(argc, argv) == GL_FALSE) {
  132. exit(1);
  133. }
  134. if (fileName == 0) {
  135. printf("No image file.\n");
  136. exit(1);
  137. }
  138. image = LoadPPM(fileName);
  139. windW = 300;
  140. windH = 300;
  141. glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH);
  142. type = GLUT_RGB;
  143. type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  144. glutInitDisplayMode(type);
  145. if (glutCreateWindow("Copy Test") == GL_FALSE) {
  146. exit(1);
  147. }
  148. Init();
  149. glutReshapeFunc(Reshape);
  150. glutKeyboardFunc(Key);
  151. glutMouseFunc(Mouse);
  152. glutDisplayFunc(Draw);
  153. glutMainLoop();
  154. return 0;
  155. }