home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / OpenGL 1.0 SDK / Source / Examples / aux / samples / shape.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  13.7 KB  |  727 lines  |  [TEXT/CWIE]

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include "tk.h"
  6. #include "aux.h"
  7.  
  8. #define OPENGL_WIDTH 24
  9. #define OPENGL_HEIGHT 13
  10.  
  11. GLubyte fly[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12. 0x03, 0x80, 0x01, 0xC0, 0x06, 0xC0, 0x03, 0x60, 0x04, 0x60, 0x06, 0x20,
  13. 0x04, 0x30, 0x0C, 0x20, 0x04, 0x18, 0x18, 0x20, 0x04, 0x0C, 0x30, 0x20,
  14. 0x04, 0x06, 0x60, 0x20, 0x44, 0x03, 0xC0, 0x22, 0x44, 0x01, 0x80, 0x22,
  15. 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22,
  16. 0x44, 0x01, 0x80, 0x22, 0x44, 0x01, 0x80, 0x22, 0x66, 0x01, 0x80, 0x66,
  17. 0x33, 0x01, 0x80, 0xCC, 0x19, 0x81, 0x81, 0x98, 0x0C, 0xC1, 0x83, 0x30,
  18. 0x07, 0xe1, 0x87, 0xe0, 0x03, 0x3f, 0xfc, 0xc0, 0x03, 0x31, 0x8c, 0xc0,
  19. 0x03, 0x33, 0xcc, 0xc0, 0x06, 0x64, 0x26, 0x60, 0x0c, 0xcc, 0x33, 0x30,
  20. 0x18, 0xcc, 0x33, 0x18, 0x10, 0xc4, 0x23, 0x08, 0x10, 0x63, 0xC6, 0x08,
  21. 0x10, 0x30, 0x0c, 0x08, 0x10, 0x18, 0x18, 0x08, 0x10, 0x00, 0x00, 0x08};
  22.  
  23. GLenum rgb, doubleBuffer, directRender, windType;
  24. GLint objectIndex     = 0;
  25. GLboolean dither      = GL_FALSE;
  26. GLint colormask       = 1;
  27. GLboolean stipple     = GL_FALSE;
  28. GLboolean smooth      = GL_FALSE;
  29. GLboolean clip        = GL_FALSE;
  30. GLboolean zbuffer     = GL_FALSE;
  31. GLboolean perspective = GL_FALSE;
  32. GLboolean light       = GL_FALSE;
  33. GLboolean cullface    = GL_TRUE;
  34. GLboolean scissor     = GL_FALSE;
  35.  
  36. GLuint bitmapBase = 0;
  37.  
  38. GLuint bases[20];
  39. GLint width, height;
  40.  
  41. GLint angleX_on = 0, angleY_on = 0, angleZ_on = 0;
  42. GLint shiftX_on = 0, shiftY_on = 0, shiftZ_on = 0;
  43.  
  44. GLfloat angleX = 0.0, angleY = 0.0, angleZ = 0.0;
  45. GLfloat scaleX = 0.25, scaleY = 0.25, scaleZ = 0.25;
  46. GLfloat shiftX = 0.0, shiftY = 0.0, shiftZ = -5.0;
  47.  
  48. static void Draw(void);
  49.  
  50. static void CreateAppleFont(void)
  51. {
  52.     bitmapBase = glGenLists(256);
  53.     aglUseFont(aglGetCurrentContext(), kFontIDNewYork, normal, 10, 0, 256, bitmapBase);
  54. }
  55.  
  56. static void DrawStr(char *str)
  57. {
  58.     glListBase(bitmapBase);
  59.     glCallLists(strlen(str), GL_UNSIGNED_BYTE, (GLubyte *) str);
  60. }
  61.  
  62. static void Init(void)
  63. {
  64.     GLdouble eqn1[4] = {0.0, 1.0, 0.0, 0.0};
  65.     GLfloat light_ambient[] = { 0.5, 0.5, 0.5, 1.0 };
  66.     GLfloat light_diffuse[] = { 0.2, 0.2, 0.4, 1.0 };
  67.     GLfloat light_specular[] = { 0.2, 0.2, 0.4, 1.0 };
  68.     /*    light_position is NOT default value    */
  69.     GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
  70.  
  71.     glLightfv (GL_LIGHT0, GL_AMBIENT, light_ambient);
  72.     glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  73.     glLightfv (GL_LIGHT0, GL_SPECULAR, light_specular);
  74.     glLightfv (GL_LIGHT0, GL_POSITION, light_position);
  75.     glLightf  (GL_LIGHT0, GL_SPOT_CUTOFF, 180.0);
  76.  
  77.     glEnable(GL_LIGHT0);
  78.     if(light)
  79.         glEnable(GL_LIGHTING);
  80.     else
  81.         glDisable(GL_LIGHTING);
  82.     
  83.     glDepthFunc(GL_LESS);
  84.     
  85.     glPolygonStipple(fly);
  86.      glLineStipple(1, 0xAA);
  87.      
  88.      if(stipple)
  89.      {
  90.          glEnable(GL_LINE_STIPPLE);
  91.          glEnable(GL_POLYGON_STIPPLE);
  92.      }
  93.      else
  94.      {
  95.          glDisable(GL_LINE_STIPPLE);
  96.          glDisable(GL_POLYGON_STIPPLE);
  97.      }
  98.      
  99.      if(zbuffer)
  100.         glEnable(GL_DEPTH_TEST);
  101.     else
  102.         glDisable(GL_DEPTH_TEST);
  103.     
  104.     if(cullface)
  105.         glEnable(GL_CULL_FACE);
  106.     else
  107.         glDisable(GL_CULL_FACE);
  108.         
  109.     if(smooth)
  110.         glShadeModel(GL_SMOOTH);
  111.     else
  112.         glShadeModel(GL_FLAT);
  113.         
  114.     if(dither)
  115.         glEnable(GL_DITHER);
  116.     else
  117.         glDisable(GL_DITHER);
  118.      
  119.      glClipPlane(GL_CLIP_PLANE0, eqn1);
  120.      
  121.      if(clip)
  122.          glEnable(GL_CLIP_PLANE0);
  123.      else
  124.         glDisable(GL_CLIP_PLANE0);
  125.         
  126.     switch(colormask)
  127.     {
  128.         case 1:
  129.             glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
  130.         break;
  131.         case 2:
  132.             glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
  133.         break;
  134.         case 3:
  135.             glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
  136.         break;
  137.         case 4:
  138.             glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
  139.         break;
  140.         case 5:
  141.             glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
  142.         break;
  143.     }
  144.  
  145.     bases[0] = glGenLists(1);
  146.     tkWireSphere(bases[0], 5.0);
  147.     
  148.     bases[1] = glGenLists(1);
  149.     tkSolidSphere(bases[1], 5.0);
  150.     
  151.     bases[2] = glGenLists(1);
  152.     tkWireCube(bases[2], 5.0);
  153.     
  154.     bases[3] = glGenLists(1);
  155.     tkSolidCube(bases[3], 5.0);
  156.     
  157.     bases[4] = glGenLists(1);
  158.     tkWireBox(bases[4], 4.0, 5.0, 6.0);
  159.     
  160.     bases[5] = glGenLists(1);
  161.     tkSolidBox(bases[5], 4.0, 5.0, 6.0);
  162.     
  163.     bases[6] = glGenLists(1);
  164.     tkWireTorus(bases[6], 2.5, 5.0);
  165.     
  166.     bases[7] = glGenLists(1);
  167.     tkSolidTorus(bases[7], 2.5, 5.0);
  168.     
  169.     bases[8] = glGenLists(1);
  170.     tkWireCylinder(bases[8], 5.0, 5.0);
  171.     
  172.     bases[9] = glGenLists(1);
  173.     tkSolidCylinder(bases[9], 5.0, 5.0);
  174.     
  175.     bases[10] = glGenLists(1);
  176.     tkWireIcosahedron(bases[10], 5.0);
  177.     
  178.     bases[11] = glGenLists(1);
  179.     tkSolidIcosahedron(bases[11], 5.0);
  180.     
  181.     bases[12] = glGenLists(1);
  182.     tkWireOctahedron(bases[12], 5.0);
  183.     
  184.     bases[13] = glGenLists(1);
  185.     tkSolidOctahedron(bases[13], 5.0);
  186.     
  187.     bases[14] = glGenLists(1);
  188.     tkWireTetrahedron(bases[14], 5.0);
  189.     
  190.     bases[15] = glGenLists(1);
  191.     tkSolidTetrahedron(bases[15], 5.0);
  192.     
  193.     bases[16] = glGenLists(1);
  194.     tkWireDodecahedron(bases[16], 5.0);
  195.     
  196.     bases[17] = glGenLists(1);
  197.     tkSolidDodecahedron(bases[17], 5.0);
  198.     
  199.     bases[18] = glGenLists(1);
  200.     tkWireCone(bases[18], 5.0, 5.0);
  201.     
  202.     bases[19] = glGenLists(1);
  203.     tkSolidCone(bases[19], 5.0, 5.0);
  204.  
  205.     glClearColor(0.0, 0.0, 0.0, 0.0);
  206.     glClearIndex(0.0);
  207.     
  208.     CreateAppleFont();
  209.     
  210.     glColor3f(1.0, 0.0, 0.0);
  211. }
  212.  
  213. static void Reshape(int w, int h)
  214. {
  215.     glViewport (0, 0, w, h);
  216.     
  217.     width  = w;
  218.     height = h;
  219.     
  220.     glMatrixMode (GL_PROJECTION);
  221.     glLoadIdentity ();
  222.     
  223.     if(perspective)
  224.     {
  225.         gluPerspective (60.0, (GLfloat)height/(GLfloat)width, 1.0, 20.0);
  226.     }
  227.     else
  228.     {
  229.         if (width <= height) 
  230.             glOrtho (-2.5, 2.5, -2.5*(GLfloat)height/(GLfloat)width, 
  231.                 2.5*(GLfloat)height/(GLfloat)width, -10.0, 10.0);
  232.         else 
  233.             glOrtho (-2.5*(GLfloat)width/(GLfloat)height, 
  234.                 2.5*(GLfloat)width/(GLfloat)height, -2.5, 2.5, -10.0, 10.0);
  235.     }
  236.             
  237.     glMatrixMode (GL_MODELVIEW);
  238. }
  239.  
  240. static void SetWireOptions(void)
  241. {
  242.     angleX_on = 0;
  243.     angleY_on = 0;
  244.     angleZ_on = 0;
  245.     
  246.     shiftX_on = 0;
  247.     shiftY_on = 0;
  248.     shiftZ_on = 0;
  249.  
  250.     scaleX = 0.25;
  251.     scaleY = 0.25;
  252.     scaleZ = 0.25;
  253.     
  254.     shiftX = 0.0;
  255.     shiftY = 0.0;
  256.     shiftZ = -5.0;
  257.     
  258.     glDisable(GL_DITHER);
  259.     dither = GL_FALSE;
  260.     
  261.     colormask = 1;
  262.     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
  263.     
  264.     glDisable(GL_LINE_STIPPLE);
  265.      glDisable(GL_POLYGON_STIPPLE);
  266.      stipple = GL_FALSE;
  267.      
  268.      glShadeModel(GL_FLAT);
  269.     smooth = GL_FALSE;
  270.     
  271.     light = GL_FALSE;
  272.     glDisable(GL_LIGHTING);
  273.     
  274.     glDisable(GL_DEPTH_TEST);
  275.     zbuffer = GL_FALSE;
  276.     
  277.     glEnable(GL_CULL_FACE);
  278.     cullface = GL_TRUE;
  279.     
  280.     glDisable(GL_CLIP_PLANE0);
  281.     clip = GL_FALSE;
  282. }
  283.  
  284. static void SetSolidOptions(void)
  285. {
  286.     angleX_on = 0;
  287.     angleY_on = 0;
  288.     angleZ_on = 0;
  289.     
  290.     shiftX_on = 0;
  291.     shiftY_on = 0;
  292.     shiftZ_on = 0;
  293.  
  294.     scaleX = 0.25;
  295.     scaleY = 0.25;
  296.     scaleZ = 0.25;
  297.     
  298.     shiftX = 0.0;
  299.     shiftY = 0.0;
  300.     shiftZ = -5.0;
  301.     
  302.     glDisable(GL_DITHER);
  303.     dither = GL_FALSE;
  304.     
  305.     colormask = 1;
  306.     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
  307.     
  308.     glDisable(GL_LINE_STIPPLE);
  309.      glDisable(GL_POLYGON_STIPPLE);
  310.      stipple = GL_FALSE;
  311.      
  312.      glShadeModel(GL_FLAT);
  313.     smooth = GL_FALSE;
  314.     
  315.     light = GL_TRUE;
  316.     glEnable(GL_LIGHTING);
  317.     
  318.     glDisable(GL_DEPTH_TEST);
  319.     zbuffer = GL_FALSE;
  320.     
  321.     glEnable(GL_CULL_FACE);
  322.     cullface = GL_TRUE;
  323.     
  324.     glDisable(GL_CLIP_PLANE0);
  325.     clip = GL_FALSE;
  326. }
  327.  
  328. static GLenum KeyDown(int key, GLenum mask)
  329. {
  330.     switch (key)
  331.     {
  332.         case TK_ESCAPE:
  333.             tkQuit();
  334.         break;
  335.         case TK_SPACE:
  336.             objectIndex++;
  337.             if(objectIndex > 19) objectIndex = 0;
  338.             
  339.             if(objectIndex % 2 == 0) SetWireOptions();
  340.             else SetSolidOptions();
  341.         break;
  342.         case TK_LEFT:
  343.             shiftX_on = -1;
  344.         break;
  345.         case TK_RIGHT:
  346.             shiftX_on = 1;
  347.         break;
  348.         case TK_UP:
  349.             shiftY_on = 1;
  350.         break;
  351.         case TK_DOWN:
  352.             shiftY_on = -1;
  353.         break;
  354.         case TK_n:
  355.             shiftZ_on = 1;
  356.         break;
  357.         case TK_m:
  358.             shiftZ_on = -1;
  359.         break;
  360.         case TK_q:
  361.             scaleX -= 0.1;
  362.             if (scaleX < 0.1) {
  363.                 scaleX = 0.1;
  364.             }
  365.         break;
  366.         case TK_w:
  367.             scaleX += 0.1;
  368.         break;
  369.         case TK_a:
  370.             scaleY -= 0.1;
  371.             if (scaleY < 0.1) {
  372.                 scaleY = 0.1;
  373.             }
  374.         break;
  375.         case TK_s:
  376.             scaleY += 0.1;
  377.         break;
  378.         case TK_z:
  379.             scaleZ -= 0.1;
  380.             if (scaleZ < 0.1) {
  381.                 scaleZ = 0.1;
  382.             }
  383.         break;
  384.         case TK_x:
  385.             scaleZ += 0.1;
  386.         break;
  387.         case TK_e:
  388.             angleX_on = -1;
  389.         break;
  390.         case TK_r:
  391.             angleX_on = 1;
  392.         break;
  393.         case TK_d:
  394.             angleY_on = -1;
  395.         break;
  396.         case TK_f:
  397.             angleY_on = 1;
  398.         break;
  399.         case TK_c:
  400.             angleZ_on = -1;
  401.         break;
  402.         case TK_v:
  403.             angleZ_on = 1;
  404.         break;
  405.         case TK_y:
  406.             if(dither)
  407.             {
  408.                 glDisable(GL_DITHER);
  409.                 dither = GL_FALSE;
  410.             }
  411.             else
  412.             {
  413.                 glEnable(GL_DITHER);
  414.                 dither = GL_TRUE;
  415.             }
  416.         break;
  417.         case TK_j:
  418.             colormask++;
  419.             if(colormask > 5) colormask = 1;
  420.             switch(colormask)
  421.             {
  422.                 case 1:
  423.                     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
  424.                 break;
  425.                 case 2:
  426.                     glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_TRUE);
  427.                 break;
  428.                 case 3:
  429.                     glColorMask(GL_TRUE, GL_FALSE, GL_TRUE, GL_TRUE);
  430.                 break;
  431.                 case 4:
  432.                     glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_TRUE);
  433.                 break;
  434.                 case 5:
  435.                     glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);
  436.                 break;
  437.             }
  438.         break;
  439.         case TK_k:
  440.             if(stipple)
  441.             {
  442.                 glDisable(GL_LINE_STIPPLE);
  443.                  glDisable(GL_POLYGON_STIPPLE);
  444.                  stipple = GL_FALSE;
  445.              }
  446.              else
  447.              {
  448.                  glEnable(GL_LINE_STIPPLE);
  449.                  glEnable(GL_POLYGON_STIPPLE);
  450.                  stipple = GL_TRUE;
  451.              }
  452.         break;
  453.         case TK_l:
  454.             if(smooth)
  455.             {
  456.                 glShadeModel(GL_FLAT);
  457.                 smooth = GL_FALSE;
  458.             }
  459.             else
  460.             {
  461.                 glShadeModel(GL_SMOOTH);
  462.                 smooth = GL_TRUE;
  463.             }
  464.         break;
  465.         case TK_h:
  466.             if(clip)
  467.             {
  468.                 glDisable(GL_CLIP_PLANE0);
  469.                 clip = GL_FALSE;
  470.             }
  471.             else
  472.             {
  473.                 glEnable(GL_CLIP_PLANE0);
  474.                 clip = GL_TRUE;
  475.             }
  476.         break;
  477.         case TK_p:
  478.             if(perspective)
  479.                 perspective = GL_FALSE;
  480.             else
  481.                 perspective = GL_TRUE;
  482.             
  483.             glMatrixMode (GL_PROJECTION);
  484.             glLoadIdentity ();
  485.     
  486.             if(perspective)
  487.             {
  488.                 gluPerspective (60.0, (GLfloat)height/(GLfloat)width, 1.0, 20.0);
  489.             }
  490.             else
  491.             {
  492.                 if (width <= height) 
  493.                     glOrtho (-2.5, 2.5, -2.5*(GLfloat)height/(GLfloat)width, 
  494.                         2.5*(GLfloat)height/(GLfloat)width, -20.0, 20.0);
  495.                 else 
  496.                     glOrtho (-2.5*(GLfloat)width/(GLfloat)height, 
  497.                         2.5*(GLfloat)width/(GLfloat)height, -2.5, 2.5, -20.0, 20.0);
  498.             }
  499.                     
  500.             glMatrixMode (GL_MODELVIEW);
  501.         break;
  502.         case TK_o:
  503.             if(light)
  504.             {
  505.                 light = GL_FALSE;
  506.                 glDisable(GL_LIGHTING);
  507.             }
  508.             else
  509.             {
  510.                 light = GL_TRUE;
  511.                 glEnable(GL_LIGHTING);
  512.             }
  513.         break;
  514.         case TK_u:
  515.             if(zbuffer)
  516.             {
  517.                 glDisable(GL_DEPTH_TEST);
  518.                 zbuffer = GL_FALSE;
  519.             }
  520.             else
  521.             {
  522.                 glEnable(GL_DEPTH_TEST);
  523.                 zbuffer = GL_TRUE;
  524.             }
  525.         break;
  526.         case TK_i:
  527.             if(cullface)
  528.             {
  529.                 glDisable(GL_CULL_FACE);
  530.                 cullface = GL_FALSE;
  531.             }
  532.             else
  533.             {
  534.                 glEnable(GL_CULL_FACE);
  535.                 cullface = GL_TRUE;
  536.             }
  537.         break;
  538.         case TK_b:
  539.             if(scissor)
  540.             {
  541.                 glDisable(GL_SCISSOR_TEST);
  542.             }
  543.             else
  544.             {
  545.                 glScissor(50, 50, 300, 300);
  546.                 glEnable(GL_SCISSOR_TEST);
  547.             }
  548.             
  549.             scissor = !scissor;
  550.         break;
  551.         default:
  552.             return GL_FALSE;
  553.     }
  554.     
  555.     return GL_TRUE;
  556. }
  557.  
  558. static double filter(double in, double *save)
  559. {
  560.     static double k1 = 0.9;
  561.     static double k2 = 0.05;
  562.  
  563.     save[3] = in;
  564.     save[1] = save[0]*k1 + k2*(save[3] + save[2]);
  565.  
  566.     save[0]=save[1];
  567.     save[2]=save[3];
  568.  
  569.     return(save[1]);
  570. }
  571.  
  572. static void Draw(void)
  573. {
  574.     static double th[4] = {0.0, 0.0, 0.0, 0.0};
  575.     static double t1 = 0.0, t2 = 0.0, t;
  576.     char num_str[200];
  577.     
  578.     t1 = t2;
  579.     
  580.     if(shiftX_on < 0)      shiftX -= 0.075;
  581.     else if(shiftX_on > 0) shiftX += 0.075;
  582.     
  583.     if(shiftY_on < 0)      shiftY -= 0.075;
  584.     else if(shiftY_on > 0) shiftY += 0.075;
  585.     
  586.     if(shiftZ_on < 0)      shiftZ -= 0.075;
  587.     else if(shiftZ_on > 0) shiftZ += 0.075;
  588.     
  589.     if(angleX_on < 0)
  590.     {
  591.         angleX -= 5.0;
  592.         if(angleX < -180.0) angleX += 360;
  593.     }
  594.     else if(angleX_on > 0)
  595.     {
  596.         angleX += 5.0;
  597.         if(angleX > 180.0) angleX -= 360;
  598.     }
  599.     
  600.     if(angleY_on < 0)
  601.     {
  602.         angleY -= 5.0;
  603.         if(angleY < -180.0) angleY += 360;
  604.     }
  605.     else if(angleY_on > 0)
  606.     {
  607.         angleY += 5.0;
  608.         if(angleY > 180.0) angleY -= 360;
  609.     }
  610.     
  611.     if(angleZ_on < 0)
  612.     {
  613.         angleZ -= 5.0;
  614.         if(angleZ < -180.0) angleZ += 360;
  615.     }
  616.     else if(angleZ_on > 0)
  617.     {
  618.         angleZ += 5.0;
  619.         if(angleZ > 180.0) angleZ -= 360;
  620.     }
  621.     
  622.     shiftX_on = 0;
  623.     shiftY_on = 0;
  624.     shiftZ_on = 0;
  625.     angleX_on = 0;
  626.     angleY_on = 0;
  627.     angleZ_on = 0;
  628.  
  629.     glClear(GL_COLOR_BUFFER_BIT);
  630.     if(zbuffer) glClear(GL_DEPTH_BUFFER_BIT);
  631.  
  632.     glMatrixMode(GL_MODELVIEW);
  633.     glPushMatrix();
  634.  
  635.     glTranslatef(shiftX, shiftY, shiftZ);
  636.     glRotatef(angleX, 1.0, 0.0, 0.0);
  637.     glRotatef(angleY, 0.0, 1.0, 0.0);
  638.     glRotatef(angleZ, 0.0, 0.0, 1.0);
  639.     glScalef(scaleX, scaleY, scaleZ);
  640.  
  641.     glCallList(bases[objectIndex]);
  642.  
  643.     glPopMatrix();
  644.  
  645.     t2 = tkNow();
  646.     t = t2 - t1;
  647.     if(t > 0.0001) t = 1.0 / t;
  648.     
  649.     if(light)   glDisable(GL_LIGHTING);
  650.     if(zbuffer) glDisable(GL_DEPTH_TEST);
  651.     
  652.     glColor3f(1.0, 0.0, 0.0);
  653.     
  654.     glMatrixMode (GL_PROJECTION);
  655.     glPushMatrix();
  656.     glLoadIdentity();
  657.     glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
  658.     
  659.     glRasterPos2f(-9.9, 9.4);
  660.     sprintf(num_str, "%0.2f Hz", filter(t, th));
  661.     DrawStr(num_str);
  662.     
  663.     glRasterPos2f(-9.9, -9.9);
  664.     sprintf(num_str, "Hit space bar for next object (read key cmds for other options)");
  665.     DrawStr(num_str);
  666.     
  667.     glPopMatrix();
  668.     glMatrixMode(GL_MODELVIEW);
  669.     
  670.     if(light)   glEnable(GL_LIGHTING);
  671.     if(zbuffer) glEnable(GL_DEPTH_TEST);
  672.     
  673.     tkSwapBuffers();
  674. }
  675.  
  676. static GLenum Args(int argc, char **argv)
  677. {
  678.     GLint i;
  679.  
  680.     rgb = GL_TRUE;
  681.     doubleBuffer = GL_TRUE;
  682.     directRender = GL_TRUE;
  683.  
  684.     for (i = 1; i < argc; i++) {
  685.     if (strcmp(argv[i], "-ci") == 0) {
  686.         rgb = GL_FALSE;
  687.     } else if (strcmp(argv[i], "-rgb") == 0) {
  688.         rgb = GL_TRUE;
  689.     } else if (strcmp(argv[i], "-sb") == 0) {
  690.         doubleBuffer = GL_FALSE;
  691.     } else if (strcmp(argv[i], "-db") == 0) {
  692.         doubleBuffer = GL_TRUE;
  693.     } else if (strcmp(argv[i], "-dr") == 0) {
  694.         directRender = GL_TRUE;
  695.     } else if (strcmp(argv[i], "-ir") == 0) {
  696.         directRender = GL_FALSE;
  697.     } else {
  698.         printf("%s (Bad option).\n", argv[i]);
  699.         return GL_FALSE;
  700.     }
  701.     }
  702.     return GL_TRUE;
  703. }
  704.  
  705. void main(int argc, char **argv)
  706. {
  707.     if(!Args(argc, argv)) tkQuit();
  708.  
  709.     tkInitPosition(30, 60, 400, 400);
  710.  
  711.     windType = (rgb) ? TK_RGB : TK_INDEX;
  712.     windType |= TK_DEPTH;
  713.     windType |= (doubleBuffer) ? TK_DOUBLE : TK_SINGLE;
  714.     windType |= (directRender) ? TK_DIRECT : TK_INDIRECT;
  715.     tkInitDisplayMode(windType);
  716.  
  717.     if(!tkInitWindow("Shape")) tkQuit();
  718.  
  719.     Init();
  720.  
  721.     tkExposeFunc(Reshape);
  722.     tkReshapeFunc(Reshape);
  723.     tkKeyDownFunc(KeyDown);
  724.     tkDisplayFunc(Draw);
  725.     tkExec();
  726. }
  727.