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