Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
1.8 KiB

  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 <windows.h>
  8. #include <GL/gl.h>
  9. #include <GL/glu.h>
  10. #include "glaux.h"
  11. static GLfloat spin = 0.0;
  12. void display(void)
  13. {
  14. glClear (GL_COLOR_BUFFER_BIT);
  15. glPushMatrix ();
  16. glRotatef (spin, 0.0, 0.0, 1.0);
  17. glRectf (-25.0, -25.0, 25.0, 25.0);
  18. glPopMatrix ();
  19. glFlush();
  20. // glXSwapBuffers (auxXDisplay(), auxXWindow());
  21. auxSwapBuffers();
  22. }
  23. void spinDisplay (void)
  24. {
  25. spin = spin + 2.0;
  26. if (spin > 360.0)
  27. spin = spin - 360.0;
  28. display();
  29. }
  30. void startIdleFunc (AUX_EVENTREC *event)
  31. {
  32. auxIdleFunc(spinDisplay);
  33. }
  34. void stopIdleFunc (AUX_EVENTREC *event)
  35. {
  36. auxIdleFunc(0);
  37. }
  38. void myinit (void)
  39. {
  40. glClearColor (0.0, 0.0, 0.0, 1.0);
  41. glColor3f (1.0, 1.0, 1.0);
  42. glShadeModel (GL_FLAT);
  43. }
  44. void myReshape(GLsizei w, GLsizei h)
  45. {
  46. glViewport(0, 0, w, h);
  47. glMatrixMode(GL_PROJECTION);
  48. glLoadIdentity();
  49. if (w <= h)
  50. glOrtho (-50.0, 50.0, -50.0*(GLfloat)h/(GLfloat)w,
  51. 50.0*(GLfloat)h/(GLfloat)w, -1.0, 1.0);
  52. else
  53. glOrtho (-50.0*(GLfloat)w/(GLfloat)h,
  54. 50.0*(GLfloat)w/(GLfloat)h, -50.0, 50.0, -1.0, 1.0);
  55. glMatrixMode(GL_MODELVIEW);
  56. glLoadIdentity ();
  57. }
  58. /* Main Loop
  59. * Open window with initial window size, title bar,
  60. * RGBA display mode, and handle input events.
  61. */
  62. int main(int argc, char** argv)
  63. {
  64. auxInitDisplayMode (AUX_DOUBLE | AUX_RGB);
  65. auxInitPosition (0, 0, 500, 500);
  66. auxInitWindow (argv[0]);
  67. myinit ();
  68. auxReshapeFunc (myReshape);
  69. auxIdleFunc (spinDisplay);
  70. auxMouseFunc (AUX_LEFTBUTTON, AUX_MOUSEDOWN, startIdleFunc);
  71. auxMouseFunc (AUX_MIDDLEBUTTON, AUX_MOUSEDOWN, stopIdleFunc);
  72. auxMainLoop(display);
  73. }