home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / newopg.zip / DOUBLE.C < prev    next >
Text File  |  1995-03-04  |  2KB  |  81 lines

  1. /*
  2.  *  double.c
  3.  *  This program demonstrates double buffering for 
  4.  *  flicker-free animation.  The left and middle mouse
  5.  *  buttons start and stop the spinning motion of the square.
  6.  */
  7. #include <GL/gl.h>
  8. #include <GL/glu.h>
  9. #include "aux.h"
  10.  
  11. static GLfloat spin = 0.0;
  12.  
  13. void display(void)
  14. {
  15.     glClear (GL_COLOR_BUFFER_BIT);
  16.  
  17.     glPushMatrix ();
  18.     glRotatef (spin, 0.0, 0.0, 1.0);
  19.     glRectf (-25.0, -25.0, 25.0, 25.0);
  20.     glPopMatrix ();
  21.     auxSwapBuffers();
  22. }
  23.  
  24. void spinDisplay (void)
  25. {
  26.     spin = spin + 2.0;
  27.     if (spin > 360.0)
  28.     spin = spin - 360.0;
  29.     display();
  30. /*    glFinish();  */
  31. }
  32.  
  33. void startIdleFunc (AUX_EVENTREC *event)
  34. {
  35.     auxIdleFunc(spinDisplay);
  36. }
  37.  
  38. void stopIdleFunc (AUX_EVENTREC *event)
  39. {
  40.     auxIdleFunc(0);
  41. }
  42.  
  43. void myinit (void)
  44. {
  45.     glClearColor (0.0, 0.0, 0.0, 1.0);
  46.     glColor3f (1.0, 1.0, 1.0);
  47.     glShadeModel (GL_FLAT);
  48. }
  49.  
  50. void myReshape(GLint w, GLint h)
  51. {
  52.     glViewport(0, 0, w, h);
  53.     glMatrixMode(GL_PROJECTION);
  54.     glLoadIdentity();
  55.     if (w <= h) 
  56.     glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w, 
  57.         50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0);
  58.     else 
  59.     glOrtho (-50.0*(GLfloat)w/(GLfloat)h, 
  60.         50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0);
  61.     glMatrixMode(GL_MODELVIEW);
  62.     glLoadIdentity ();
  63. }
  64.  
  65. /*  Main Loop
  66.  *  Open window with initial window size, title bar, 
  67.  *  RGBA display mode, and handle input events.
  68.  */
  69. int main(int argc, char** argv)
  70. {
  71.     auxInitDisplayMode (AUX_DOUBLE | AUX_RGB);
  72.     auxInitPosition (0, 0, 500, 500);
  73.     auxInitWindow (argv[0]);
  74.     myinit ();
  75.     auxReshapeFunc (myReshape);
  76.     auxIdleFunc (spinDisplay);
  77.     auxMouseFunc (AUX_LEFTBUTTON, AUX_MOUSEDOWN, startIdleFunc);
  78.     auxMouseFunc (AUX_MIDDLEBUTTON, AUX_MOUSEDOWN, stopIdleFunc);
  79.     auxMainLoop(display);
  80. }
  81.