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.

265 lines
7.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 "tk.h"
  41. #define OPENGL_WIDTH 24
  42. #define OPENGL_HEIGHT 13
  43. GLenum rgb, doubleBuffer, directRender, windType;
  44. float boxA[3] = {
  45. 0, 0, 0
  46. };
  47. float boxB[3] = {
  48. -100, 0, 0
  49. };
  50. float boxC[3] = {
  51. 100, 0, 0
  52. };
  53. float boxD[3] = {
  54. 0, 95, 0
  55. };
  56. float boxE[3] = {
  57. 0, -105, 0
  58. };
  59. GLubyte OpenGL_bits1[] = {
  60. 0x00, 0x03, 0x00,
  61. 0x7f, 0xfb, 0xff,
  62. 0x7f, 0xfb, 0xff,
  63. 0x00, 0x03, 0x00,
  64. 0x3e, 0x8f, 0xb7,
  65. 0x63, 0xdb, 0xb0,
  66. 0x63, 0xdb, 0xb7,
  67. 0x63, 0xdb, 0xb6,
  68. 0x63, 0x8f, 0xf3,
  69. 0x63, 0x00, 0x00,
  70. 0x63, 0x00, 0x00,
  71. 0x63, 0x00, 0x00,
  72. 0x3e, 0x00, 0x00,
  73. };
  74. GLubyte OpenGL_bits2[] = {
  75. 0x00, 0x00, 0x00,
  76. 0xff, 0xff, 0x01,
  77. 0xff, 0xff, 0x01,
  78. 0x00, 0x00, 0x00,
  79. 0xf9, 0xfc, 0x01,
  80. 0x8d, 0x0d, 0x00,
  81. 0x8d, 0x0d, 0x00,
  82. 0x8d, 0x0d, 0x00,
  83. 0xcc, 0x0d, 0x00,
  84. 0x0c, 0x4c, 0x0a,
  85. 0x0c, 0x4c, 0x0e,
  86. 0x8c, 0xed, 0x0e,
  87. 0xf8, 0x0c, 0x00,
  88. };
  89. GLubyte logo_bits[] = {
  90. 0x00, 0x66, 0x66,
  91. 0xff, 0x66, 0x66,
  92. 0x00, 0x00, 0x00,
  93. 0xff, 0x3c, 0x3c,
  94. 0x00, 0x42, 0x40,
  95. 0xff, 0x42, 0x40,
  96. 0x00, 0x41, 0x40,
  97. 0xff, 0x21, 0x20,
  98. 0x00, 0x2f, 0x20,
  99. 0xff, 0x20, 0x20,
  100. 0x00, 0x10, 0x90,
  101. 0xff, 0x10, 0x90,
  102. 0x00, 0x0f, 0x10,
  103. 0xff, 0x00, 0x00,
  104. 0x00, 0x66, 0x66,
  105. 0xff, 0x66, 0x66,
  106. };
  107. static void Init(void)
  108. {
  109. glClearColor(0.0, 0.0, 0.0, 0.0);
  110. glClearIndex(0.0);
  111. }
  112. static void Reshape(int width, int height)
  113. {
  114. glViewport(0, 0, (GLint)width, (GLint)height);
  115. glMatrixMode(GL_PROJECTION);
  116. glLoadIdentity();
  117. gluOrtho2D(-175, 175, -175, 175);
  118. glMatrixMode(GL_MODELVIEW);
  119. }
  120. static GLenum Key(int key, GLenum mask)
  121. {
  122. switch (key) {
  123. case TK_ESCAPE:
  124. tkQuit();
  125. }
  126. return GL_FALSE;
  127. }
  128. static void Draw(void)
  129. {
  130. float mapI[2], mapIA[2], mapIR[2];
  131. glClear(GL_COLOR_BUFFER_BIT);
  132. mapI[0] = 0.0;
  133. mapI[1] = 1.0;
  134. mapIR[0] = 0.0;
  135. mapIR[1] = 0.0;
  136. mapIA[0] = 1.0;
  137. mapIA[1] = 1.0;
  138. glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 2, mapIR);
  139. glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 2, mapI);
  140. glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 2, mapI);
  141. glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 2, mapIA);
  142. glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
  143. TK_SETCOLOR(windType, TK_WHITE);
  144. glRasterPos3fv(boxA);
  145. glPixelStorei(GL_UNPACK_ROW_LENGTH, 24);
  146. glPixelStorei(GL_UNPACK_SKIP_PIXELS, 8);
  147. glPixelStorei(GL_UNPACK_SKIP_ROWS, 2);
  148. glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
  149. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  150. glBitmap(16, 12, 8.0, 0.0, 0.0, 0.0, logo_bits);
  151. glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
  152. glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
  153. glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
  154. glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE);
  155. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  156. TK_SETCOLOR(windType, TK_WHITE);
  157. glRasterPos3fv(boxB);
  158. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  159. OpenGL_bits1);
  160. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  161. OpenGL_bits2);
  162. TK_SETCOLOR(windType, TK_YELLOW);
  163. glRasterPos3fv(boxC);
  164. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  165. OpenGL_bits1);
  166. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  167. OpenGL_bits2);
  168. TK_SETCOLOR(windType, TK_CYAN);
  169. glRasterPos3fv(boxD);
  170. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  171. OpenGL_bits1);
  172. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  173. OpenGL_bits2);
  174. TK_SETCOLOR(windType, TK_RED);
  175. glRasterPos3fv(boxE);
  176. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  177. OpenGL_bits1);
  178. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  179. OpenGL_bits2);
  180. glFlush();
  181. if (doubleBuffer) {
  182. tkSwapBuffers();
  183. }
  184. }
  185. static GLenum Args(int argc, char **argv)
  186. {
  187. GLint i;
  188. rgb = GL_TRUE;
  189. doubleBuffer = GL_FALSE;
  190. directRender = GL_FALSE;
  191. for (i = 1; i < argc; i++) {
  192. if (strcmp(argv[i], "-ci") == 0) {
  193. rgb = GL_FALSE;
  194. } else if (strcmp(argv[i], "-rgb") == 0) {
  195. rgb = GL_TRUE;
  196. } else if (strcmp(argv[i], "-sb") == 0) {
  197. doubleBuffer = GL_FALSE;
  198. } else if (strcmp(argv[i], "-db") == 0) {
  199. doubleBuffer = GL_TRUE;
  200. } else if (strcmp(argv[i], "-dr") == 0) {
  201. directRender = GL_TRUE;
  202. } else if (strcmp(argv[i], "-ir") == 0) {
  203. directRender = GL_FALSE;
  204. } else {
  205. printf("%s (Bad option).\n", argv[i]);
  206. return GL_FALSE;
  207. }
  208. }
  209. return GL_TRUE;
  210. }
  211. void main(int argc, char **argv)
  212. {
  213. if (Args(argc, argv) == GL_FALSE) {
  214. tkQuit();
  215. }
  216. tkInitPosition(0, 0, 300, 300);
  217. windType = (rgb) ? TK_RGB : TK_INDEX;
  218. windType |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  219. windType |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  220. tkInitDisplayMode(windType);
  221. if (tkInitWindow("Bitmap Test") == GL_FALSE) {
  222. tkQuit();
  223. }
  224. Init();
  225. tkExposeFunc(Reshape);
  226. tkReshapeFunc(Reshape);
  227. tkKeyDownFunc(Key);
  228. tkDisplayFunc(Draw);
  229. tkExec();
  230. }