b069bea91ccdffa457c6974fc576271dfabc3859
[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/glut.h>
29
30
31 static GLint Window[2];
32
33 static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
34 static GLboolean Anim = GL_TRUE;
35
36
37 static void Idle( void )
38 {
39 Xrot += 3.0;
40 Yrot += 4.0;
41 Zrot += 2.0;
42
43 glutSetWindow(Window[0]);
44 glutPostRedisplay();
45 glutSetWindow(Window[1]);
46 glutPostRedisplay();
47 }
48
49
50 static void Display0( void )
51 {
52 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
53
54 glEnable(GL_LIGHTING);
55 glEnable(GL_LIGHT0);
56 glEnable(GL_DEPTH_TEST);
57
58 glPushMatrix();
59 glRotatef(Xrot, 1, 0, 0);
60 glRotatef(Yrot, 0, 1, 0);
61 glRotatef(Zrot, 0, 0, 1);
62
63 glColor3f(0, 1, 0);
64 glutSolidCube(2.0);
65
66 glPopMatrix();
67
68 glutSwapBuffers();
69 }
70
71
72 static void Display1( void )
73 {
74 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
75
76 glPushMatrix();
77 glRotatef(Xrot, 1, 0, 0);
78 glRotatef(Yrot, 0, 1, 0);
79 glRotatef(Zrot, 0, 0, 1);
80
81 glShadeModel(GL_FLAT);
82
83 glBegin(GL_TRIANGLE_STRIP);
84 glColor3f(1, 0, 0);
85 glVertex2f(-1, -1);
86 glVertex2f( 1, -1);
87 glColor3f(1, 0, 0);
88 glVertex2f( -1, 1);
89 glColor3f(0, 0, 1);
90 glVertex2f( 1, 1);
91 glEnd();
92
93 glPopMatrix();
94
95 glutSwapBuffers();
96 }
97
98
99 static void Reshape( int width, int height )
100 {
101 glViewport( 0, 0, width, height );
102 glMatrixMode( GL_PROJECTION );
103 glLoadIdentity();
104 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
105 glMatrixMode( GL_MODELVIEW );
106 glLoadIdentity();
107 glTranslatef( 0.0, 0.0, -15.0 );
108 }
109
110
111 static void Key( unsigned char key, int x, int y )
112 {
113 const GLfloat step = 3.0;
114 (void) x;
115 (void) y;
116 switch (key) {
117 case 'a':
118 Anim = !Anim;
119 if (Anim)
120 glutIdleFunc(Idle);
121 else
122 glutIdleFunc(NULL);
123 break;
124 case 'z':
125 Zrot -= step;
126 break;
127 case 'Z':
128 Zrot += step;
129 break;
130 case 27:
131 exit(0);
132 break;
133 }
134 glutPostRedisplay();
135 }
136
137
138
139
140 int main( int argc, char *argv[] )
141 {
142 glutInit( &argc, argv );
143
144 glutInitWindowPosition( 0, 0 );
145 glutInitWindowSize( 400, 400 );
146 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
147 Window[0] = glutCreateWindow(argv[0]);
148 glutReshapeFunc( Reshape );
149 glutKeyboardFunc( Key );
150 glutDisplayFunc( Display0 );
151 glutIdleFunc(Idle);
152 printf("GL_RENDERER[0] = %s\n", (char *) glGetString(GL_RENDERER));
153
154 glutInitWindowPosition( 500, 0 );
155 glutInitWindowSize( 400, 400 );
156 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
157 Window[1] = glutCreateWindow(argv[0]);
158 glutReshapeFunc( Reshape );
159 glutKeyboardFunc( Key );
160 glutDisplayFunc( Display1 );
161 glutIdleFunc(Idle);
162 printf("GL_RENDERER[1] = %s\n", (char *) glGetString(GL_RENDERER));
163
164 glutMainLoop();
165
166 return 0;
167 }