home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue28 / opengl / AuxTest / AuxTest.dpr next >
Encoding:
Text File  |  1997-11-09  |  2.7 KB  |  112 lines

  1. program AuxTest;
  2.  
  3. uses Windows, OpenGL, GLAux;
  4.  
  5. {$R *.RES}
  6.  
  7. var
  8.     cSelection: Char;
  9.  
  10. { Callback routine - called when window changes size }
  11.  
  12. procedure ChangeSize (w, h: GLsizei); stdcall;
  13. begin
  14.     // Prevent a divide by zero
  15.     if h = 0 then h := 1;
  16.  
  17.     // Set viewport and clipping volume
  18.     glViewport (0, 0, w, h);
  19.     glLoadIdentity;
  20.     if w <= h then glOrtho (-100.0, 100.0, -100.0, 100.0 * h / w, -100.0, 100.0)
  21.     else glOrtho (-100.0, 100 * w / h, -100.0, 100.0, -100.0, 100.00);
  22. end;
  23.  
  24. { Callback routine - called by AUX library to render the scene }
  25.  
  26. procedure RenderScene; stdcall;
  27. begin
  28.     // Clear the screen
  29.     glClear (GL_Color_Buffer_Bit);
  30.  
  31.     // Rotate one degree around each axis
  32.     // (Note we don't call LoadIdentity() so
  33.     // this rotation is cumulative
  34.     glRotatef (1.0,1.0,0.0,0.0);
  35.     glRotatef (1.0,0.0,1.0,0.0);
  36.     glRotatef (1.0,0.0,0.0,1.0);
  37.  
  38.     // Draw the selected object
  39.     case cSelection of
  40.         'a':    auxWireCone (30.0, 75.0);
  41.         'b':    auxWireCylinder (30.0, 75.0);
  42.         'c':    auxWireDodecahedron (75.0);
  43.     'd':    auxWireIcosahedron (75.0);
  44.         'e':    auxWireOctahedron (75.0);
  45.         'f':    auxWireSphere (75.0);
  46.         'g':    auxWireTeapot (50.0);
  47.         'h':    auxWireTetrahedron (75.0);
  48.         'i':    auxWireTorus (20.0, 50.0);
  49.         'j':    auxWireCube (75.0);
  50.         'k':    auxWireBox (75.0,75.0,75.0);
  51.     end;
  52.  
  53.     glFlush;
  54.     // Swap drawing to screen
  55.     auxSwapBuffers;
  56. end;
  57.  
  58. procedure Main;
  59. begin
  60.     // Display a menu of objects to draw
  61.     Writeln ('Select Wire object to draw:');
  62.     Writeln;
  63.     Writeln ('a - Cone');
  64.     Writeln ('b - Cylinder');
  65.     Writeln ('c - Dodecahedron');
  66.     Writeln ('d - Icosahedron');
  67.     Writeln ('e - Octahedron');
  68.     Writeln ('f - Sphere');
  69.     Writeln ('g - Teapot');
  70.     Writeln ('h - Tetrahedron');
  71.     Writeln ('i - Torus');
  72.     Writeln ('j - Cube');
  73.     Writeln ('k - Box');
  74.  
  75.     // Validate and accept selection
  76.     cSelection := #0;
  77.     while not (cSelection in ['a'..'k']) do begin
  78.         Writeln;
  79.         Write ('Selection: ');
  80.     Readln (cSelection);
  81.     end;
  82.  
  83.     // Setup the AUX library window for double buffer
  84.     auxInitDisplayMode (Aux_Double or Aux_RGBA);
  85.     auxInitPosition (100, 100, 250, 250);
  86.     auxInitWindow ('3D Aux library objects');
  87.  
  88.     // Set background to blue
  89.     glClearColor (0.0, 0.0, 1.0, 1.0);
  90.  
  91.     // Set drawing color to Red
  92.     glColor3f (1.0, 0.0, 0.0);
  93.  
  94.     // Establish window resize function
  95.     auxReshapeFunc (@ChangeSize);
  96.  
  97.     // Establish idle function
  98.     auxIdleFunc (@RenderScene);
  99.  
  100.     // Start main loop
  101.     auxMainLoop (@RenderScene);
  102. end;
  103.  
  104. begin
  105.     Main;
  106. end.
  107.  
  108.  
  109.  
  110.  
  111.  
  112.