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