home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / oglgold.zip / SAMPLES / TK / ACCUM.C < prev    next >
C/C++ Source or Header  |  1997-09-30  |  3KB  |  139 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "tk.h"
  5.  
  6.  
  7. GLenum doubleBuffer, directRender;
  8. GLint thing1, thing2;
  9.  
  10.  
  11. static void Init(void)
  12. {
  13.  
  14.     glClearColor(0.0, 0.0, 0.0, 0.0);
  15.     glClearAccum(0.0, 0.0, 0.0, 0.0);
  16.  
  17.     thing1 = glGenLists(1);
  18.     glNewList(thing1, GL_COMPILE);
  19.     glColor3f(1.0, 0.0, 0.0);
  20.     glRectf(-1.0, -1.0, 1.0, 0.0);
  21.     glEndList();
  22.  
  23.     thing2 = glGenLists(1);
  24.     glNewList(thing2, GL_COMPILE);
  25.     glColor3f(0.0, 1.0, 0.0);
  26.     glRectf(0.0, -1.0, 1.0, 1.0);
  27.     glEndList();
  28. }
  29.  
  30. static void Reshape(int width, int height)
  31. {
  32.  
  33.     glViewport(0, 0, (GLint)width, (GLint)height);
  34.  
  35.     glMatrixMode(GL_PROJECTION);
  36.     glLoadIdentity();
  37.     glMatrixMode(GL_MODELVIEW);
  38.     glLoadIdentity();
  39. }
  40.  
  41. static GLenum Key(int key, GLenum mask)
  42. {
  43.  
  44.     switch (key) {
  45.       case TK_B:
  46.         tkClipBoard();
  47.         break;
  48.       case TK_ESCAPE:
  49.     tkQuit();
  50.       case TK_1:
  51.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  52.     break;
  53.       case TK_2:
  54.     glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  55.     break;
  56.       default:
  57.     return GL_FALSE;
  58.     }
  59.     return GL_TRUE;
  60. }
  61.  
  62. static void Draw(void)
  63. {
  64.  
  65.     glPushMatrix();
  66.  
  67.     glScalef(0.8, 0.8, 1.0);
  68.  
  69.     glClear(GL_COLOR_BUFFER_BIT);
  70.     glCallList(thing1);
  71.     glAccum(GL_LOAD, 0.5);
  72.  
  73.     glClear(GL_COLOR_BUFFER_BIT);
  74.     glCallList(thing2);
  75.     glAccum(GL_ACCUM, 0.5);
  76.  
  77.     glAccum(GL_RETURN, 1.0);
  78.  
  79.     glPopMatrix();
  80.  
  81.     glFlush();
  82.  
  83.     if (doubleBuffer) {
  84.     tkSwapBuffers();
  85.     }
  86. }
  87.  
  88. static GLenum Args(int argc, char **argv)
  89. {
  90.     GLint i;
  91.  
  92.     doubleBuffer = GL_FALSE;
  93.     directRender = GL_TRUE;
  94.  
  95.     for (i = 1; i < argc; i++) {
  96.     if (strcmp(argv[i], "-sb") == 0) {
  97.         doubleBuffer = GL_FALSE;
  98.     } else if (strcmp(argv[i], "-db") == 0) {
  99.         doubleBuffer = GL_TRUE;
  100.     } else if (strcmp(argv[i], "-dr") == 0) {
  101.         directRender = GL_TRUE;
  102.     } else if (strcmp(argv[i], "-ir") == 0) {
  103.         directRender = GL_FALSE;
  104.     } else {
  105.         printf("%s (Bad option).\n", argv[i]);
  106.         return GL_FALSE;
  107.     }
  108.     }
  109.     return GL_TRUE;
  110. }
  111.  
  112. void main(int argc, char **argv)
  113. {
  114.     GLenum type;
  115.  
  116.     if (Args(argc, argv) == GL_FALSE) {
  117.     tkQuit();
  118.     }
  119.  
  120.     tkInitPosition(0, 0, 300, 300);
  121.  
  122.     type = TK_RGB | TK_ACCUM;
  123.     type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  124.     type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  125.     tkInitDisplayMode(type);
  126.  
  127.     if (tkInitWindow("Accum Test") == GL_FALSE) {
  128.     tkQuit();
  129.     }
  130.  
  131.     Init();
  132.  
  133.     tkExposeFunc(Reshape);
  134.     tkReshapeFunc(Reshape);
  135.     tkKeyDownFunc(Key);
  136.     tkDisplayFunc(Draw);
  137.     tkExec();
  138. }
  139.