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