Clone of mesa.
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.

multiwindow.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * A skeleton/template GLUT program
  3. *
  4. * Written by Brian Paul and in the public domain.
  5. */
  6. /*
  7. * Revision 1.1 2001/08/21 14:25:31 brianp
  8. * simple multi-window GLUT test prog
  9. *
  10. * Revision 1.1.1.1 1999/08/19 00:55:42 jtg
  11. * Imported sources
  12. *
  13. * Revision 1.2 1998/11/07 14:20:14 brianp
  14. * added simple rotation, animation of cube
  15. *
  16. * Revision 1.1 1998/11/07 14:14:37 brianp
  17. * Initial revision
  18. *
  19. */
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <math.h>
  23. #include <GL/glut.h>
  24. static GLint Window[2];
  25. static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
  26. static GLboolean Anim = GL_TRUE;
  27. static void Idle( void )
  28. {
  29. Xrot += 3.0;
  30. Yrot += 4.0;
  31. Zrot += 2.0;
  32. glutSetWindow(Window[0]);
  33. glutPostRedisplay();
  34. glutSetWindow(Window[1]);
  35. glutPostRedisplay();
  36. }
  37. static void Display0( void )
  38. {
  39. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  40. glEnable(GL_LIGHTING);
  41. glEnable(GL_LIGHT0);
  42. glEnable(GL_DEPTH_TEST);
  43. glPushMatrix();
  44. glRotatef(Xrot, 1, 0, 0);
  45. glRotatef(Yrot, 0, 1, 0);
  46. glRotatef(Zrot, 0, 0, 1);
  47. glColor3f(0, 1, 0);
  48. glutSolidCube(2.0);
  49. glPopMatrix();
  50. glutSwapBuffers();
  51. }
  52. static void Display1( void )
  53. {
  54. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  55. glPushMatrix();
  56. glRotatef(Xrot, 1, 0, 0);
  57. glRotatef(Yrot, 0, 1, 0);
  58. glRotatef(Zrot, 0, 0, 1);
  59. glShadeModel(GL_FLAT);
  60. glBegin(GL_TRIANGLE_STRIP);
  61. glColor3f(1, 0, 0);
  62. glVertex2f(-1, -1);
  63. glVertex2f( 1, -1);
  64. glColor3f(1, 0, 0);
  65. glVertex2f( -1, 1);
  66. glColor3f(0, 0, 1);
  67. glVertex2f( 1, 1);
  68. glEnd();
  69. glPopMatrix();
  70. glutSwapBuffers();
  71. }
  72. static void Reshape( int width, int height )
  73. {
  74. glViewport( 0, 0, width, height );
  75. glMatrixMode( GL_PROJECTION );
  76. glLoadIdentity();
  77. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  78. glMatrixMode( GL_MODELVIEW );
  79. glLoadIdentity();
  80. glTranslatef( 0.0, 0.0, -15.0 );
  81. }
  82. static void Key( unsigned char key, int x, int y )
  83. {
  84. const GLfloat step = 3.0;
  85. (void) x;
  86. (void) y;
  87. switch (key) {
  88. case 'a':
  89. Anim = !Anim;
  90. if (Anim)
  91. glutIdleFunc(Idle);
  92. else
  93. glutIdleFunc(NULL);
  94. break;
  95. case 'z':
  96. Zrot -= step;
  97. break;
  98. case 'Z':
  99. Zrot += step;
  100. break;
  101. case 27:
  102. exit(0);
  103. break;
  104. }
  105. glutPostRedisplay();
  106. }
  107. int main( int argc, char *argv[] )
  108. {
  109. glutInit( &argc, argv );
  110. glutInitWindowPosition( 0, 0 );
  111. glutInitWindowSize( 400, 400 );
  112. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  113. Window[0] = glutCreateWindow(argv[0]);
  114. glutReshapeFunc( Reshape );
  115. glutKeyboardFunc( Key );
  116. glutDisplayFunc( Display0 );
  117. glutIdleFunc(Idle);
  118. printf("GL_RENDERER[0] = %s\n", (char *) glGetString(GL_RENDERER));
  119. glutInitWindowPosition( 500, 0 );
  120. glutInitWindowSize( 400, 400 );
  121. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  122. Window[1] = glutCreateWindow(argv[0]);
  123. glutReshapeFunc( Reshape );
  124. glutKeyboardFunc( Key );
  125. glutDisplayFunc( Display1 );
  126. glutIdleFunc(Idle);
  127. printf("GL_RENDERER[1] = %s\n", (char *) glGetString(GL_RENDERER));
  128. glutMainLoop();
  129. return 0;
  130. }