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.

bitmap1.c 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. #define OPENGL_WIDTH 24
  29. #define OPENGL_HEIGHT 13
  30. GLenum rgb, doubleBuffer, windType;
  31. float boxA[3] = {
  32. 0, 0, 0
  33. };
  34. float boxB[3] = {
  35. -100, 0, 0
  36. };
  37. float boxC[3] = {
  38. 100, 0, 0
  39. };
  40. float boxD[3] = {
  41. 0, 95, 0
  42. };
  43. float boxE[3] = {
  44. 0, -105, 0
  45. };
  46. GLubyte OpenGL_bits1[] = {
  47. 0x00, 0x03, 0x00,
  48. 0x7f, 0xfb, 0xff,
  49. 0x7f, 0xfb, 0xff,
  50. 0x00, 0x03, 0x00,
  51. 0x3e, 0x8f, 0xb7,
  52. 0x63, 0xdb, 0xb0,
  53. 0x63, 0xdb, 0xb7,
  54. 0x63, 0xdb, 0xb6,
  55. 0x63, 0x8f, 0xf3,
  56. 0x63, 0x00, 0x00,
  57. 0x63, 0x00, 0x00,
  58. 0x63, 0x00, 0x00,
  59. 0x3e, 0x00, 0x00,
  60. };
  61. GLubyte OpenGL_bits2[] = {
  62. 0x00, 0x00, 0x00,
  63. 0xff, 0xff, 0x01,
  64. 0xff, 0xff, 0x01,
  65. 0x00, 0x00, 0x00,
  66. 0xf9, 0xfc, 0x01,
  67. 0x8d, 0x0d, 0x00,
  68. 0x8d, 0x0d, 0x00,
  69. 0x8d, 0x0d, 0x00,
  70. 0xcc, 0x0d, 0x00,
  71. 0x0c, 0x4c, 0x0a,
  72. 0x0c, 0x4c, 0x0e,
  73. 0x8c, 0xed, 0x0e,
  74. 0xf8, 0x0c, 0x00,
  75. };
  76. GLubyte logo_bits[] = {
  77. 0x00, 0x66, 0x66,
  78. 0xff, 0x66, 0x66,
  79. 0x00, 0x00, 0x00,
  80. 0xff, 0x3c, 0x3c,
  81. 0x00, 0x42, 0x40,
  82. 0xff, 0x42, 0x40,
  83. 0x00, 0x41, 0x40,
  84. 0xff, 0x21, 0x20,
  85. 0x00, 0x2f, 0x20,
  86. 0xff, 0x20, 0x20,
  87. 0x00, 0x10, 0x90,
  88. 0xff, 0x10, 0x90,
  89. 0x00, 0x0f, 0x10,
  90. 0xff, 0x00, 0x00,
  91. 0x00, 0x66, 0x66,
  92. 0xff, 0x66, 0x66,
  93. };
  94. #include "tkmap.c"
  95. static void Init(void)
  96. {
  97. glClearColor(0.0, 0.0, 0.0, 0.0);
  98. glClearIndex(0.0);
  99. }
  100. static void Reshape(int width, int height)
  101. {
  102. glViewport(0, 0, (GLint)width, (GLint)height);
  103. glMatrixMode(GL_PROJECTION);
  104. glLoadIdentity();
  105. gluOrtho2D(-175, 175, -175, 175);
  106. glMatrixMode(GL_MODELVIEW);
  107. }
  108. static void Key(unsigned char key, int x, int y)
  109. {
  110. switch (key) {
  111. case 27:
  112. exit(1);
  113. }
  114. }
  115. static void Draw(void)
  116. {
  117. float mapI[2], mapIA[2], mapIR[2];
  118. glClear(GL_COLOR_BUFFER_BIT);
  119. mapI[0] = 0.0;
  120. mapI[1] = 1.0;
  121. mapIR[0] = 0.0;
  122. mapIR[1] = 0.0;
  123. mapIA[0] = 1.0;
  124. mapIA[1] = 1.0;
  125. glPixelMapfv(GL_PIXEL_MAP_I_TO_R, 2, mapIR);
  126. glPixelMapfv(GL_PIXEL_MAP_I_TO_G, 2, mapI);
  127. glPixelMapfv(GL_PIXEL_MAP_I_TO_B, 2, mapI);
  128. glPixelMapfv(GL_PIXEL_MAP_I_TO_A, 2, mapIA);
  129. glPixelTransferi(GL_MAP_COLOR, GL_TRUE);
  130. SetColor(COLOR_WHITE);
  131. glRasterPos3fv(boxA);
  132. glPixelStorei(GL_UNPACK_ROW_LENGTH, 24);
  133. glPixelStorei(GL_UNPACK_SKIP_PIXELS, 8);
  134. glPixelStorei(GL_UNPACK_SKIP_ROWS, 2);
  135. glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
  136. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  137. glBitmap(16, 12, 8.0, 0.0, 0.0, 0.0, logo_bits);
  138. glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
  139. glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
  140. glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
  141. glPixelStorei(GL_UNPACK_LSB_FIRST, GL_TRUE);
  142. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  143. SetColor(COLOR_WHITE);
  144. glRasterPos3fv(boxB);
  145. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  146. OpenGL_bits1);
  147. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  148. OpenGL_bits2);
  149. SetColor(COLOR_YELLOW);
  150. glRasterPos3fv(boxC);
  151. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  152. OpenGL_bits1);
  153. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  154. OpenGL_bits2);
  155. SetColor(COLOR_CYAN);
  156. glRasterPos3fv(boxD);
  157. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  158. OpenGL_bits1);
  159. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  160. OpenGL_bits2);
  161. SetColor(COLOR_RED);
  162. glRasterPos3fv(boxE);
  163. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  164. OpenGL_bits1);
  165. glBitmap(OPENGL_WIDTH, OPENGL_HEIGHT, OPENGL_WIDTH, 0.0, OPENGL_WIDTH, 0.0,
  166. OpenGL_bits2);
  167. glFlush();
  168. if (doubleBuffer) {
  169. glutSwapBuffers();
  170. }
  171. }
  172. static GLenum Args(int argc, char **argv)
  173. {
  174. GLint i;
  175. rgb = GL_TRUE;
  176. doubleBuffer = GL_FALSE;
  177. for (i = 1; i < argc; i++) {
  178. if (strcmp(argv[i], "-ci") == 0) {
  179. rgb = GL_FALSE;
  180. } else if (strcmp(argv[i], "-rgb") == 0) {
  181. rgb = GL_TRUE;
  182. } else if (strcmp(argv[i], "-sb") == 0) {
  183. doubleBuffer = GL_FALSE;
  184. } else if (strcmp(argv[i], "-db") == 0) {
  185. doubleBuffer = GL_TRUE;
  186. } else {
  187. printf("%s (Bad option).\n", argv[i]);
  188. return GL_FALSE;
  189. }
  190. }
  191. return GL_TRUE;
  192. }
  193. int main(int argc, char **argv)
  194. {
  195. glutInit(&argc, argv);
  196. if (Args(argc, argv) == GL_FALSE) {
  197. exit(1);
  198. }
  199. glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
  200. windType = (rgb) ? GLUT_RGB : GLUT_INDEX;
  201. windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  202. glutInitDisplayMode(windType);
  203. if (glutCreateWindow("Bitmap Test") == GL_FALSE) {
  204. exit(1);
  205. }
  206. InitMap();
  207. Init();
  208. glutReshapeFunc(Reshape);
  209. glutKeyboardFunc(Key);
  210. glutDisplayFunc(Draw);
  211. glutMainLoop();
  212. return 0;
  213. }