Source code of Windows XP (NT5)
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.

209 lines
5.0 KiB

  1. /*
  2. * (c) Copyright 1993, 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(TM) is a trademark of Silicon Graphics, Inc.
  36. */
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <stdlib.h>
  40. #include <sys/types.h>
  41. #include <sys/stat.h>
  42. #include <fcntl.h>
  43. //#include <unistd.h>
  44. #include "tk.h"
  45. GLenum doubleBuffer, directRender;
  46. GLint windW, windH;
  47. char *fileName = 0;
  48. TK_RGBImageRec *image;
  49. float point[3];
  50. float zoom;
  51. GLint x, y;
  52. static void Init(void)
  53. {
  54. glClearColor(0.0, 0.0, 0.0, 0.0);
  55. x = 0;
  56. y = windH;
  57. zoom = 1.8;
  58. }
  59. static void Reshape(int width, int height)
  60. {
  61. windW = (GLint)width;
  62. windH = (GLint)height;
  63. glViewport(0, 0, windW, windH);
  64. glMatrixMode(GL_PROJECTION);
  65. glLoadIdentity();
  66. gluOrtho2D(0, windW, 0, windH);
  67. glMatrixMode(GL_MODELVIEW);
  68. }
  69. static GLenum Key(int key, GLenum mask)
  70. {
  71. switch (key) {
  72. case TK_ESCAPE:
  73. tkQuit();
  74. case TK_Z:
  75. zoom += 0.2;
  76. break;
  77. case TK_z:
  78. zoom -= 0.2;
  79. if (zoom < 0.2) {
  80. zoom = 0.2;
  81. }
  82. break;
  83. default:
  84. return GL_FALSE;
  85. }
  86. return GL_TRUE;
  87. }
  88. static GLenum Mouse(int mouseX, int mouseY, GLenum button)
  89. {
  90. x = (GLint)mouseX;
  91. y = (GLint)mouseY;
  92. return GL_TRUE;
  93. }
  94. static void Draw(void)
  95. {
  96. glClear(GL_COLOR_BUFFER_BIT);
  97. point[0] = (windW / 2) - (image->sizeX / 2);
  98. point[1] = (windH / 2) - (image->sizeY / 2);
  99. point[2] = 0;
  100. glRasterPos3fv(point);
  101. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  102. glPixelZoom(1.0, 1.0);
  103. glDrawPixels(image->sizeX, image->sizeY, GL_RGB, GL_UNSIGNED_BYTE,
  104. image->data);
  105. point[0] = (float)x;
  106. point[1] = windH - (float)y;
  107. point[2] = 0.0;
  108. glRasterPos3fv(point);
  109. glPixelZoom(zoom, zoom);
  110. glCopyPixels((windW/2)-(image->sizeX/2),
  111. (windH/2)-(image->sizeY/2),
  112. image->sizeX, image->sizeY, GL_COLOR);
  113. glFlush();
  114. if (doubleBuffer) {
  115. tkSwapBuffers();
  116. }
  117. }
  118. static GLenum Args(int argc, char **argv)
  119. {
  120. GLint i;
  121. doubleBuffer = GL_FALSE;
  122. directRender = GL_FALSE;
  123. for (i = 1; i < argc; i++) {
  124. if (strcmp(argv[i], "-sb") == 0) {
  125. doubleBuffer = GL_FALSE;
  126. } else if (strcmp(argv[i], "-db") == 0) {
  127. doubleBuffer = GL_TRUE;
  128. } else if (strcmp(argv[i], "-dr") == 0) {
  129. directRender = GL_TRUE;
  130. } else if (strcmp(argv[i], "-ir") == 0) {
  131. directRender = GL_FALSE;
  132. } else if (strcmp(argv[i], "-f") == 0) {
  133. if (i+1 >= argc || argv[i+1][0] == '-') {
  134. printf("-f (No file name).\n");
  135. return GL_FALSE;
  136. } else {
  137. fileName = argv[++i];
  138. }
  139. } else {
  140. printf("%s (Bad option).\n", argv[i]);
  141. return GL_FALSE;
  142. }
  143. }
  144. return GL_TRUE;
  145. }
  146. void main(int argc, char **argv)
  147. {
  148. GLenum type;
  149. if (Args(argc, argv) == GL_FALSE) {
  150. tkQuit();
  151. }
  152. if (fileName == 0) {
  153. printf("No image file.\n");
  154. tkQuit();
  155. }
  156. image = tkRGBImageLoad(fileName);
  157. windW = 300;
  158. windH = 300;
  159. tkInitPosition(0, 0, windW, windH);
  160. type = TK_RGB;
  161. type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  162. type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  163. tkInitDisplayMode(type);
  164. if (tkInitWindow("Copy Test") == GL_FALSE) {
  165. tkQuit();
  166. }
  167. Init();
  168. tkExposeFunc(Reshape);
  169. tkReshapeFunc(Reshape);
  170. tkKeyDownFunc(Key);
  171. tkMouseDownFunc(Mouse);
  172. tkDisplayFunc(Draw);
  173. tkExec();
  174. }