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