Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

multiwindow.c 3.2KB

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