home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / samples / bitmap1.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  6KB  |  253 lines

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