home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / OpenGL 1.0 SDK / Source / Examples / aux / samples / bitmap1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  5.0 KB  |  225 lines  |  [TEXT/CWIE]

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