home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible / OpenGL_Superbible_Waite_Group_Press_1996.iso / book / chapt3 / scale / scale.c next >
C/C++ Source or Header  |  1996-03-08  |  1KB  |  63 lines

  1. // Scale.c
  2. // Scaling an OpenGL Window.
  3.  
  4. #include <windows.h>    // Standard Windows header
  5. #include <gl\gl.h>        // OpenGL Library
  6. #include <gl\glaux.h>    // AUX Library
  7.  
  8.  
  9. // Called by AUX Library when the window has changed size
  10. void CALLBACK ChangeSize(GLsizei w, GLsizei h)
  11.     {
  12.     // Prevent a divide by zero
  13.     if(h == 0)
  14.         h = 1;
  15.         
  16.     // Set Viewport to window dimensions
  17.     glViewport(0, 0, w, h);
  18.  
  19.     // Reset coordinate system
  20.     glLoadIdentity();
  21.  
  22.     // Establish clipping volume (left, right, bottom, top, near, far)
  23.     if (w <= h) 
  24.         glOrtho (0.0f, 250.0f, 0.0f, 250.0f*h/w, 1.0, -1.0);
  25.     else 
  26.         glOrtho (0.0f, 250.0f*w/h, 0.0f, 250.0f, 1.0, -1.0);
  27.  
  28.     }
  29.  
  30. // Called by the AUX Library whenever the window 
  31. // needs to be updated
  32. void CALLBACK RenderScene(void)
  33.     {
  34.     // Set background color to blue
  35.     glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
  36.  
  37.     // OpenGL or AUX Library drawing code
  38.     glClear(GL_COLOR_BUFFER_BIT);
  39.  
  40.     // Draws a Red Rectangle
  41.     glColor3f(1.0f, 0.0f, 0.0f);
  42.     glRectf(100.0f, 150.0f, 150.0f, 100.0f);
  43.  
  44.     glFlush();
  45.     }
  46.  
  47.  
  48.  
  49. void main(void)
  50.     {
  51.     // Setup and initialize AUX window
  52.     auxInitDisplayMode(AUX_SINGLE | AUX_RGBA);
  53.     auxInitPosition(100,100,250,250);
  54.     auxInitWindow("Scaling Window");
  55.  
  56.     // Set function to call when window changes size
  57.     auxReshapeFunc(ChangeSize);
  58.  
  59.     // Set function to call when window needs updating
  60.     auxMainLoop(RenderScene);
  61.     }
  62.  
  63.