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

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