home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / newopg.zip / CURSOR.C < prev    next >
Text File  |  1995-03-04  |  3KB  |  175 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "tk.h"
  5.  
  6.  
  7. GLenum rgb, doubleBuffer, directRender, windType;
  8. int windX, windY;
  9. int cursor;
  10. GLubyte shape[] = {
  11.     0x00, 0x00,
  12.     0x7F, 0xFE,
  13.     0x40, 0x02,
  14.     0x40, 0x02,
  15.     0x40, 0x02,
  16.     0x40, 0x02,
  17.     0x40, 0x02,
  18.     0x40, 0x02,
  19.     0x40, 0x02,
  20.     0x40, 0x02,
  21.     0x40, 0x02,
  22.     0x40, 0x02,
  23.     0x40, 0x02,
  24.     0x40, 0x02,
  25.     0x7F, 0xFE,
  26.     0x00, 0x00
  27. };
  28. GLubyte mask[] = {
  29.     0xFF, 0xFF,
  30.     0xFF, 0xFF,
  31.     0xFF, 0xFF,
  32.     0xE0, 0x07,
  33.     0xE0, 0x07,
  34.     0xE0, 0x07,
  35.     0xE0, 0x07,
  36.     0xE0, 0x07,
  37.     0xE0, 0x07,
  38.     0xE0, 0x07,
  39.     0xE0, 0x07,
  40.     0xE0, 0x07,
  41.     0xE0, 0x07,
  42.     0xFF, 0xFF,
  43.     0xFF, 0xFF,
  44.     0xFF, 0xFF
  45. };
  46.  
  47.  
  48. static void Init(void)
  49. {
  50.     int i;
  51.  
  52.     for (i = TK_BLACK; i <= TK_WHITE; i++) {
  53.     tkNewCursor(i, shape, mask, i, TK_WHITE, 0, 0);
  54.     }
  55.     for (i = TK_BLACK; i <= TK_WHITE; i++) {
  56.     tkNewCursor(i+TK_WHITE, shape, mask, TK_WHITE, i, 0, 0);
  57.     }
  58.     cursor = TK_BLACK;
  59.     tkSetCursor(cursor);
  60.     glClearColor(0.0, 0.0, 0.0, 0.0);
  61.     glClearIndex(0.0);
  62. }
  63.  
  64. static void Reshape(int width, int height)
  65. {
  66.  
  67.     windX = width;
  68.     windY = height;
  69.     glViewport(0, 0, windX, windY);
  70.  
  71.     glMatrixMode(GL_PROJECTION);
  72.     glLoadIdentity();
  73.     gluOrtho2D(0.,(float) windX, 0., (float)windY);
  74.     glMatrixMode(GL_MODELVIEW);
  75. }
  76.  
  77. static GLenum Key(int key, GLenum mask)
  78. {
  79.  
  80.     switch (key) {
  81.       case TK_ESCAPE:
  82.         tkQuit();
  83.       case TK_SPACE:
  84.     cursor++;
  85.     if (cursor > TK_WHITE*2) {
  86.         cursor = TK_BLACK;
  87.     }
  88.     tkSetCursor(cursor);
  89.       default:
  90.     return GL_FALSE;
  91.     }
  92.     return GL_TRUE;
  93. }
  94.  
  95. static void Draw(void)
  96. {
  97.  
  98.     glClear(GL_COLOR_BUFFER_BIT);
  99.  
  100.     glBegin(GL_POLYGON);
  101.     TK_SETCOLOR(windType, TK_BLACK);
  102.     glVertex2i(0, 0);
  103.     TK_SETCOLOR(windType, TK_RED);
  104.     glVertex2i(windX, 0);
  105.     TK_SETCOLOR(windType, TK_GREEN);
  106.     glVertex2i(windX, windY);
  107.     TK_SETCOLOR(windType, TK_BLUE);
  108.     glVertex2i(0, windY);
  109.     glEnd();
  110.  
  111.     glFlush();
  112.  
  113.     if (doubleBuffer) {
  114.     tkSwapBuffers();
  115.     }
  116. }
  117.  
  118. static GLenum Args(int argc, char **argv)
  119. {
  120.     GLint i;
  121.  
  122.     rgb = GL_TRUE;
  123.     doubleBuffer = GL_FALSE;
  124.     directRender = GL_TRUE;
  125.  
  126.     for (i = 1; i < argc; i++) {
  127.     if (strcmp(argv[i], "-ci") == 0) {
  128.         rgb = GL_FALSE;
  129.     } else if (strcmp(argv[i], "-rgb") == 0) {
  130.         rgb = GL_TRUE;
  131.     } else if (strcmp(argv[i], "-sb") == 0) {
  132.         doubleBuffer = GL_FALSE;
  133.     } else if (strcmp(argv[i], "-db") == 0) {
  134.         doubleBuffer = GL_TRUE;
  135.     } else if (strcmp(argv[i], "-dr") == 0) {
  136.         directRender = GL_TRUE;
  137.     } else if (strcmp(argv[i], "-ir") == 0) {
  138.         directRender = GL_FALSE;
  139.     } else {
  140.         printf("%s (Bad option).\n", argv[i]);
  141.         return GL_FALSE;
  142.     }
  143.     }
  144.     return GL_TRUE;
  145. }
  146.  
  147. void main(int argc, char **argv)
  148. {
  149.  
  150.     if (Args(argc, argv) == GL_FALSE) {
  151.     tkQuit();
  152.     }
  153.  
  154.     windX = 300;
  155.     windY = 300;
  156.     tkInitPosition(0, 0, windX, windY);
  157.  
  158.     windType = (rgb) ? TK_RGB : TK_INDEX;
  159.     windType |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  160.     windType |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  161.     tkInitDisplayMode(windType);
  162.  
  163.     if (tkInitWindow("Cursor Test") == GL_FALSE) {
  164.     tkQuit();
  165.     }
  166.  
  167.     Init();
  168.  
  169.     tkExposeFunc(Reshape);
  170.     tkReshapeFunc(Reshape);
  171.     tkKeyDownFunc(Key);
  172.     tkDisplayFunc(Draw);
  173.     tkExec();
  174. }
  175.