home *** CD-ROM | disk | FTP | other *** search
/ Aminet 10 / aminetcdnumber101996.iso / Aminet / gfx / x11 / Mesa_Amiwin.lha / Mesa-Amiwin / samples / wave.c < prev   
C/C++ Source or Header  |  1995-10-03  |  15KB  |  600 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 <math.h>
  29. #include "gltk.h"
  30.  
  31.  
  32. #define PI 3.14159265358979323846
  33.  
  34. #define GETCOORD(frame, x, y) (&(theMesh.coords[frame*theMesh.numCoords+(x)+(y)*(theMesh.widthX+1)]))
  35. #define GETFACET(frame, x, y) (&(theMesh.facets[frame*theMesh.numFacets+(x)+(y)*theMesh.widthX]))
  36.  
  37.  
  38. GLenum rgb, doubleBuffer, directRender;
  39.  
  40. GLint colorIndexes1[3];
  41. GLint colorIndexes2[3];
  42. GLenum clearMask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
  43.  
  44. GLenum smooth = GL_FALSE;
  45. GLenum lighting = GL_TRUE;
  46. GLenum depth = GL_TRUE;
  47. GLenum stepMode = GL_FALSE;
  48. GLenum spinMode = GL_FALSE;
  49. GLint contouring = 0;
  50.  
  51. GLint widthX, widthY;
  52. GLint checkerSize;
  53. float height;
  54.  
  55. GLint frames, curFrame = 0, nextFrame = 0;
  56.  
  57. struct facet {
  58.     float color[3];
  59.     float normal[3];
  60. };
  61. struct coord {
  62.     float vertex[3];
  63.     float normal[3];
  64. };
  65. struct mesh {
  66.     GLint widthX, widthY;
  67.     GLint numFacets;
  68.     GLint numCoords;
  69.     GLint frames;
  70.     struct coord *coords;
  71.     struct facet *facets;
  72. } theMesh;
  73.  
  74. GLubyte contourTexture1[] = {
  75.     255, 255, 255, 255,
  76.     255, 255, 255, 255,
  77.     255, 255, 255, 255,
  78.     127, 127, 127, 127,
  79. };
  80. GLubyte contourTexture2[] = {
  81.     255, 255, 255, 255,
  82.     255, 127, 127, 127,
  83.     255, 127, 127, 127,
  84.     255, 127, 127, 127,
  85. };
  86.  
  87.  
  88. static void Animate(void)
  89. {
  90.     struct coord *coord;
  91.     struct facet *facet;
  92.     float *lastColor;
  93.     float *thisColor;
  94.     GLint i, j;
  95.  
  96.     glClear(clearMask);
  97.  
  98.     if (nextFrame || !stepMode) {
  99.     curFrame++;
  100.     }
  101.     if (curFrame >= theMesh.frames) {
  102.     curFrame = 0;
  103.     }
  104.  
  105.     if ((nextFrame || !stepMode) && spinMode) {
  106.     glRotatef(5.0, 0.0, 0.0, 1.0);
  107.     }
  108.     nextFrame = 0;
  109.  
  110.     for (i = 0; i < theMesh.widthX; i++) {
  111.     glBegin(GL_QUAD_STRIP);
  112.     lastColor = NULL;
  113.     for (j = 0; j < theMesh.widthY; j++) {
  114.         facet = GETFACET(curFrame, i, j);
  115.         if (!smooth && lighting) {
  116.         glNormal3fv(facet->normal);
  117.         }
  118.         if (lighting) {
  119.         if (rgb) {
  120.             thisColor = facet->color;
  121.             glColor3fv(facet->color);
  122.         } else {
  123.             thisColor = facet->color;
  124.             glMaterialfv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES, 
  125.                  facet->color);
  126.         }
  127.         } else {
  128.         if (rgb) {
  129.             thisColor = facet->color;
  130.             glColor3fv(facet->color);
  131.         } else {
  132.             thisColor = facet->color;
  133.             glIndexf(facet->color[1]);
  134.         }
  135.         }
  136.  
  137.         if (!lastColor || (thisColor[0] != lastColor[0] && smooth)) {
  138.         if (lastColor) {
  139.             glEnd();
  140.             glBegin(GL_QUAD_STRIP);
  141.         }
  142.         coord = GETCOORD(curFrame, i, j);
  143.         if (smooth && lighting) {
  144.             glNormal3fv(coord->normal);
  145.         }
  146.         glVertex3fv(coord->vertex);
  147.  
  148.         coord = GETCOORD(curFrame, i+1, j);
  149.         if (smooth && lighting) {
  150.             glNormal3fv(coord->normal);
  151.         }
  152.         glVertex3fv(coord->vertex);
  153.         }
  154.  
  155.         coord = GETCOORD(curFrame, i, j+1);
  156.         if (smooth && lighting) {
  157.         glNormal3fv(coord->normal);
  158.         }
  159.         glVertex3fv(coord->vertex);
  160.  
  161.         coord = GETCOORD(curFrame, i+1, j+1);
  162.         if (smooth && lighting) {
  163.         glNormal3fv(coord->normal);
  164.         }
  165.         glVertex3fv(coord->vertex);
  166.  
  167.         lastColor = thisColor;
  168.     }
  169.     glEnd();
  170.     }
  171.  
  172.     glFlush();
  173.     if (doubleBuffer) {
  174.     tkSwapBuffers();
  175.     }
  176. }
  177.  
  178. static void SetColorMap(void) 
  179. {
  180.     static float green[3] = {0.2, 1.0, 0.2};
  181.     static float red[3] = {1.0, 0.2, 0.2};
  182.     float *color, percent;
  183.     GLint *indexes, entries, i, j;
  184.     long buf[4];
  185.  
  186.     entries = tkGetColorMapSize();
  187.  
  188.     colorIndexes1[0] = 1;
  189.     colorIndexes1[1] = 1 + (GLint)((entries - 1) * 0.3);
  190.     colorIndexes1[2] = (GLint)((entries - 1) * 0.5);
  191.     colorIndexes2[0] = 1 + (GLint)((entries - 1) * 0.5);
  192.     colorIndexes2[1] = 1 + (GLint)((entries - 1) * 0.8);
  193.     colorIndexes2[2] = entries - 1;
  194.  
  195.     for (i = 0; i < 2; i++) {
  196.     switch (i) {
  197.       case 0:
  198.         color = green;
  199.         indexes = colorIndexes1;
  200.         break;
  201.       case 1:
  202.         color = red;
  203.         indexes = colorIndexes2;
  204.         break;
  205.     }
  206.  
  207.     for (j = indexes[0]; j < indexes[1]; j++) {
  208.         percent = 0.2 + 0.8 * (j - indexes[0]) /
  209.               (float)(indexes[1] - indexes[0]);
  210.         tkSetOneColor(j, percent*color[0], percent*color[1],
  211.                percent*color[2]);
  212.     }
  213.     for (j=indexes[1]; j<=indexes[2]; j++) {
  214.         percent = (j - indexes[1]) / (float)(indexes[2] - indexes[1]);
  215.         tkSetOneColor(j, percent*(1-color[0])+color[0],
  216.                percent*(1-color[1])+color[1],
  217.                percent*(1-color[2])+color[2]);
  218.     }
  219.     }
  220. }
  221.  
  222. static void InitMesh(void)
  223. {
  224.     struct coord *coord;
  225.     struct facet *facet;
  226.     float dp1[3], dp2[3];
  227.     float *pt1, *pt2, *pt3;
  228.     float angle, d, x, y;
  229.     GLint numFacets, numCoords, frameNum, i, j;
  230.  
  231.     theMesh.widthX = widthX;
  232.     theMesh.widthY = widthY;
  233.     theMesh.frames = frames;
  234.  
  235.     numFacets = widthX * widthY;
  236.     numCoords = (widthX + 1) * (widthY + 1);
  237.  
  238.     theMesh.numCoords = numCoords;
  239.     theMesh.numFacets = numFacets;
  240.  
  241.     theMesh.coords = (struct coord *)malloc(frames*numCoords*
  242.                         sizeof(struct coord));
  243.     theMesh.facets = (struct facet *)malloc(frames*numFacets*
  244.                         sizeof(struct facet));
  245.     if (theMesh.coords == NULL || theMesh.facets == NULL) {
  246.     printf("Out of memory.\n");
  247.     tkQuit();
  248.     }
  249.  
  250.     for (frameNum = 0; frameNum < frames; frameNum++) {
  251.     for (i = 0; i <= widthX; i++) {
  252.         x = i / (float)widthX;
  253.         for (j = 0; j <= widthY; j++) {
  254.         y = j / (float)widthY;
  255.  
  256.         d = sqrt(x*x+y*y);
  257.         if (d == 0.0) {
  258.             d = 0.0001;
  259.         }
  260.         angle = 2 * PI * d + (2 * PI / frames * frameNum);
  261.  
  262.         coord = GETCOORD(frameNum, i, j);
  263.  
  264.         coord->vertex[0] = x - 0.5;
  265.         coord->vertex[1] = y - 0.5;
  266.         coord->vertex[2] = (height - height * d) * cos(angle);
  267.  
  268.         coord->normal[0] = -(height / d) * x * ((1 - d) * 2 * PI *
  269.                    sin(angle) + cos(angle));
  270.         coord->normal[1] = -(height / d) * y * ((1 - d) * 2 * PI *
  271.                    sin(angle) + cos(angle));
  272.         coord->normal[2] = -1;
  273.  
  274.         d = 1.0 / sqrt(coord->normal[0]*coord->normal[0]+
  275.                    coord->normal[1]*coord->normal[1]+1);
  276.         coord->normal[0] *= d;
  277.         coord->normal[1] *= d;
  278.         coord->normal[2] *= d;
  279.         }
  280.     }
  281.     for (i = 0; i < widthX; i++) {
  282.         for (j = 0; j < widthY; j++) {
  283.         facet = GETFACET(frameNum, i, j);
  284.         if (((i/checkerSize)%2)^(j/checkerSize)%2) {
  285.             if (rgb) {
  286.             facet->color[0] = 1.0;
  287.             facet->color[1] = 0.2;
  288.             facet->color[2] = 0.2;
  289.             } else {
  290.             facet->color[0] = colorIndexes1[0];
  291.             facet->color[1] = colorIndexes1[1];
  292.             facet->color[2] = colorIndexes1[2];
  293.             }
  294.         } else {
  295.             if (rgb) {
  296.             facet->color[0] = 0.2;
  297.             facet->color[1] = 1.0;
  298.             facet->color[2] = 0.2;
  299.             } else {
  300.             facet->color[0] = colorIndexes2[0];
  301.             facet->color[1] = colorIndexes2[1];
  302.             facet->color[2] = colorIndexes2[2];
  303.             }
  304.         }
  305.         pt1 = GETCOORD(frameNum, i, j)->vertex;
  306.         pt2 = GETCOORD(frameNum, i, j+1)->vertex;
  307.         pt3 = GETCOORD(frameNum, i+1, j+1)->vertex;
  308.  
  309.         dp1[0] = pt2[0] - pt1[0];
  310.         dp1[1] = pt2[1] - pt1[1];
  311.         dp1[2] = pt2[2] - pt1[2];
  312.  
  313.         dp2[0] = pt3[0] - pt2[0];
  314.         dp2[1] = pt3[1] - pt2[1];
  315.         dp2[2] = pt3[2] - pt2[2];
  316.  
  317.         facet->normal[0] = dp1[1] * dp2[2] - dp1[2] * dp2[1];
  318.         facet->normal[1] = dp1[2] * dp2[0] - dp1[0] * dp2[2];
  319.         facet->normal[2] = dp1[0] * dp2[1] - dp1[1] * dp2[0];
  320.  
  321.         d = 1.0 / sqrt(facet->normal[0]*facet->normal[0]+
  322.                    facet->normal[1]*facet->normal[1]+
  323.                    facet->normal[2]*facet->normal[2]);
  324.  
  325.         facet->normal[0] *= d;
  326.         facet->normal[1] *= d;
  327.         facet->normal[2] *= d;
  328.         }
  329.     }
  330.     }
  331. }
  332.  
  333. static void InitMaterials(void)
  334. {
  335.     static float ambient[] = {0.1, 0.1, 0.1, 1.0};
  336.     static float diffuse[] = {0.5, 1.0, 1.0, 1.0};
  337.     static float position[] = {90.0, 90.0, 150.0, 0.0};
  338.     static float front_mat_shininess[] = {60.0};
  339.     static float front_mat_specular[] = {0.2, 0.2, 0.2, 1.0};
  340.     static float front_mat_diffuse[] = {0.5, 0.28, 0.38, 1.0};
  341.     static float back_mat_shininess[] = {60.0};
  342.     static float back_mat_specular[] = {0.5, 0.5, 0.2, 1.0};
  343.     static float back_mat_diffuse[] = {1.0, 1.0, 0.2, 1.0};
  344.     static float lmodel_ambient[] = {1.0, 1.0, 1.0, 1.0};
  345.     static float lmodel_twoside[] = {GL_TRUE};
  346.  
  347.     glMatrixMode(GL_PROJECTION);
  348.     gluPerspective(450, 1.0, 0.5, 10.0);
  349.  
  350.     glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  351.     glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  352.     glLightfv(GL_LIGHT0, GL_POSITION, position);
  353.     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  354.     glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
  355.     glEnable(GL_LIGHTING);
  356.     glEnable(GL_LIGHT0);
  357.     
  358.     glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess);
  359.     glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular);
  360.     glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
  361.     glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess);
  362.     glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular);
  363.     glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);
  364.     if (rgb) {
  365.     glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
  366.     }
  367.  
  368.     if (rgb) {
  369.     glEnable(GL_COLOR_MATERIAL);
  370.     } else {
  371.     SetColorMap();
  372.     }
  373. }
  374.  
  375. static void InitTexture(void)
  376. {
  377.  
  378.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
  379.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  380.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  381.     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  382.     glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  383. }
  384.  
  385. static void Init(void)
  386. {
  387.  
  388.     glClearColor(0.0, 0.0, 0.0, 0.0);
  389.  
  390.     glShadeModel(GL_FLAT);
  391.     
  392.     glFrontFace(GL_CW);
  393.  
  394.     glEnable(GL_DEPTH_TEST);
  395.  
  396.     InitMaterials();
  397.     InitTexture();
  398.     InitMesh();
  399.  
  400.     glMatrixMode(GL_MODELVIEW);
  401.     glTranslatef(0.0, 0.4, -1.8);
  402.     glScalef(2.0, 2.0, 2.0);
  403.     glRotatef(-35.0, 1.0, 0.0, 0.0);
  404.     glRotatef(35.0, 0.0, 0.0, 1.0);
  405. }
  406.  
  407. static void Reshape(int width, int height)
  408. {
  409.  
  410.     glViewport(0, 0, (GLint)width, (GLint)height);
  411. }
  412.  
  413. static GLenum Key(int key, GLenum mask)
  414. {
  415.  
  416.     switch (key) {
  417.       case TK_ESCAPE:
  418.     tkQuit();
  419.       case TK_c:
  420.     contouring++;
  421.     if (contouring == 1) {
  422.         static GLfloat map[4] = {0, 0, 20, 0};
  423.  
  424.         glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0, GL_LUMINANCE,
  425.              GL_UNSIGNED_BYTE, (GLvoid *)contourTexture1);
  426.         glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
  427.         glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
  428.         glTexGenfv(GL_S, GL_OBJECT_PLANE, map);
  429.         glTexGenfv(GL_T, GL_OBJECT_PLANE, map);
  430.         glEnable(GL_TEXTURE_2D);
  431.         glEnable(GL_TEXTURE_GEN_S);
  432.         glEnable(GL_TEXTURE_GEN_T);
  433.     } else if (contouring == 2) {
  434.         static GLfloat map[4] = {0, 0, 20, 0};
  435.  
  436.         glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
  437.         glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
  438.         glPushMatrix();
  439.         glMatrixMode(GL_MODELVIEW);
  440.         glLoadIdentity();
  441.         glTexGenfv(GL_S, GL_EYE_PLANE, map);
  442.         glTexGenfv(GL_T, GL_EYE_PLANE, map);
  443.         glPopMatrix();
  444.     } else {
  445.         contouring = 0;
  446.         glDisable(GL_TEXTURE_GEN_S);
  447.         glDisable(GL_TEXTURE_GEN_T);
  448.         glDisable(GL_TEXTURE_2D);
  449.     }
  450.     break;
  451.       case TK_s:
  452.     smooth = !smooth;
  453.     if (smooth) {
  454.         glShadeModel(GL_SMOOTH);
  455.     } else {
  456.         glShadeModel(GL_FLAT);
  457.     }
  458.     break;
  459.       case TK_l:
  460.     lighting = !lighting;
  461.     if (lighting) {
  462.         glEnable(GL_LIGHTING);
  463.         glEnable(GL_LIGHT0);
  464.         if (rgb) {
  465.         glEnable(GL_COLOR_MATERIAL);
  466.         }
  467.     } else {
  468.         glDisable(GL_LIGHTING);
  469.         glDisable(GL_LIGHT0);
  470.         if (rgb) {
  471.         glDisable(GL_COLOR_MATERIAL);
  472.         }
  473.     }
  474.     break;
  475.       case TK_d:
  476.     depth = !depth;
  477.     if (depth) {
  478.         glEnable(GL_DEPTH_TEST);
  479.         clearMask |= GL_DEPTH_BUFFER_BIT;
  480.     } else {
  481.         glDisable(GL_DEPTH_TEST);
  482.         clearMask &= ~GL_DEPTH_BUFFER_BIT;
  483.     }
  484.     break;
  485.       case TK_SPACE:
  486.     stepMode = !stepMode;
  487.     if (stepMode) {
  488.         tkIdleFunc(0);
  489.         tkDisplayFunc(Animate);
  490.     } else {
  491.         tkIdleFunc(Animate);
  492.         tkDisplayFunc(0);
  493.     }
  494.     break;
  495.       case TK_n:
  496.     if (stepMode) {
  497.         nextFrame = 1;
  498.     }
  499.     break;
  500.       case TK_a:
  501.     spinMode = !spinMode;
  502.     break;
  503.       default:
  504.     return GL_FALSE;
  505.     }
  506.     return GL_TRUE;
  507. }
  508.  
  509. static GLenum Args(int argc, char **argv)
  510. {
  511.     GLint i;
  512.  
  513.     rgb = GL_TRUE;
  514.     doubleBuffer = GL_FALSE;
  515.     directRender = GL_TRUE;
  516.     frames = 10;
  517.     widthX = 10;
  518.     widthY = 10;
  519.     checkerSize = 2;
  520.     height = 0.2;
  521.  
  522.     for (i = 1; i < argc; i++) {
  523.     if (strcmp(argv[i], "-ci") == 0) {
  524.         rgb = GL_FALSE;
  525.     } else if (strcmp(argv[i], "-rgb") == 0) {
  526.         rgb = GL_TRUE;
  527.     } else if (strcmp(argv[i], "-sb") == 0) {
  528.         doubleBuffer = GL_FALSE;
  529.     } else if (strcmp(argv[i], "-db") == 0) {
  530.         doubleBuffer = GL_TRUE;
  531.     } else if (strcmp(argv[i], "-dr") == 0) {
  532.         directRender = GL_TRUE;
  533.     } else if (strcmp(argv[i], "-ir") == 0) {
  534.         directRender = GL_FALSE;
  535.     } else if (strcmp(argv[i], "-grid") == 0) {
  536.         if (i+2 >= argc || argv[i+1][0] == '-' || argv[i+2][0] == '-') {
  537.         printf("-grid (No numbers).\n");
  538.         return GL_FALSE;
  539.         } else {
  540.         widthX = atoi(argv[++i]);
  541.         widthY = atoi(argv[++i]);
  542.         }
  543.     } else if (strcmp(argv[i], "-size") == 0) {
  544.         if (i+1 >= argc || argv[i+1][0] == '-') {
  545.         printf("-checker (No number).\n");
  546.         return GL_FALSE;
  547.         } else {
  548.         checkerSize = atoi(argv[++i]);
  549.         }
  550.     } else if (strcmp(argv[i], "-wave") == 0) {
  551.         if (i+1 >= argc || argv[i+1][0] == '-') {
  552.         printf("-wave (No number).\n");
  553.         return GL_FALSE;
  554.         } else {
  555.         height = atof(argv[++i]);
  556.         }
  557.     } else if (strcmp(argv[i], "-frames") == 0) {
  558.         if (i+1 >= argc || argv[i+1][0] == '-') {
  559.         printf("-frames (No number).\n");
  560.         return GL_FALSE;
  561.         } else {
  562.         frames = atoi(argv[++i]);
  563.         }
  564.     } else {
  565.         printf("%s (Bad option).\n", argv[i]);
  566.         return GL_FALSE;
  567.     }
  568.     }
  569.     return GL_TRUE;
  570. }
  571.  
  572. void main(int argc, char **argv)
  573. {
  574.     GLenum type;
  575.  
  576.     if (Args(argc, argv) == GL_FALSE) {
  577.     tkQuit();
  578.     }
  579.  
  580.     tkInitPosition(0, 0, 300, 300);
  581.  
  582.     type = TK_DEPTH;
  583.     type |= (rgb) ? TK_RGB : TK_INDEX;
  584.     type |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  585.     type |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  586.     tkInitDisplayMode(type);
  587.  
  588.     if (tkInitWindow("Wave Demo") == GL_FALSE) {
  589.     tkQuit();
  590.     }
  591.  
  592.     Init();
  593.  
  594.     tkExposeFunc(Reshape);
  595.     tkReshapeFunc(Reshape);
  596.     tkKeyDownFunc(Key);
  597.     tkIdleFunc(Animate);
  598.     tkExec();
  599. }
  600.