fixed compiler warnings
[mesa.git] / progs / demos / glutfx.c
1 /* $Id: glutfx.c,v 1.2 2000/06/27 17:04:43 brianp Exp $ */
2
3 /*
4 * Example of how one might use GLUT with the 3Dfx driver in full-screen mode.
5 * Note: this only works with X since we're using Mesa's GLX "hack" for
6 * using Glide.
7 *
8 * Goals:
9 * easy setup and input event handling with GLUT
10 * use 3Dfx hardware
11 * automatically set MESA environment variables
12 * don't lose mouse input focus
13 *
14 * Brian Paul This file is in the public domain.
15 */
16
17 /*
18 * $Log: glutfx.c,v $
19 * Revision 1.2 2000/06/27 17:04:43 brianp
20 * fixed compiler warnings
21 *
22 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
23 * Imported sources
24 *
25 * Revision 3.2 1999/03/28 18:18:33 brianp
26 * minor clean-up
27 *
28 * Revision 3.1 1998/06/29 02:37:30 brianp
29 * minor changes for Windows (Ted Jump)
30 *
31 * Revision 3.0 1998/02/14 18:42:29 brianp
32 * initial rev
33 *
34 */
35
36
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <math.h>
40 #include <GL/glut.h>
41
42
43 #define WIDTH 640
44 #define HEIGHT 480
45
46
47 static int Window = 0;
48 static int ScreenWidth, ScreenHeight;
49 static GLuint Torus = 0;
50 static GLfloat Xrot = 0.0, Yrot = 0.0;
51
52
53
54 static void Display( void )
55 {
56 static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0};
57 static GLfloat red[4] = {1.0, 0.2, 0.2, 1.0};
58 static GLfloat green[4] = {0.2, 1.0, 0.2, 1.0};
59
60 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
61
62 glPushMatrix();
63 glRotatef(Xrot, 1, 0, 0);
64 glRotatef(Yrot, 0, 1, 0);
65
66 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
67 glCallList(Torus);
68
69 glRotatef(90.0, 1, 0, 0);
70 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
71 glCallList(Torus);
72
73 glRotatef(90.0, 0, 1, 0);
74 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green);
75 glCallList(Torus);
76
77 glPopMatrix();
78
79 glutSwapBuffers();
80 }
81
82
83 static void Reshape( int width, int height )
84 {
85 float ratio = (float) width / (float) height;
86
87 ScreenWidth = width;
88 ScreenHeight = height;
89
90 /*
91 * The 3Dfx driver is limited to 640 x 480 but the X window may be larger.
92 * Enforce that here.
93 */
94 if (width > WIDTH)
95 width = WIDTH;
96 if (height > HEIGHT)
97 height = HEIGHT;
98
99 glViewport( 0, 0, width, height );
100 glMatrixMode( GL_PROJECTION );
101 glLoadIdentity();
102 glFrustum( -ratio, ratio, -1.0, 1.0, 5.0, 30.0 );
103 glMatrixMode( GL_MODELVIEW );
104 glLoadIdentity();
105 glTranslatef( 0.0, 0.0, -20.0 );
106 }
107
108
109 static void Key( unsigned char key, int x, int y )
110 {
111 (void) x;
112 (void) y;
113 switch (key) {
114 case 27:
115 glutDestroyWindow(Window);
116 exit(0);
117 break;
118 }
119 glutPostRedisplay();
120 }
121
122
123 static void SpecialKey( int key, int x, int y )
124 {
125 (void) x;
126 (void) y;
127 switch (key) {
128 case GLUT_KEY_UP:
129 break;
130 case GLUT_KEY_DOWN:
131 break;
132 case GLUT_KEY_LEFT:
133 break;
134 case GLUT_KEY_RIGHT:
135 break;
136 }
137 glutPostRedisplay();
138 }
139
140
141 static void MouseMove( int x, int y )
142 {
143 Xrot = y - ScreenWidth / 2;
144 Yrot = x - ScreenHeight / 2;
145 glutPostRedisplay();
146 }
147
148
149 static void Init( void )
150 {
151 Torus = glGenLists(1);
152 glNewList(Torus, GL_COMPILE);
153 glutSolidTorus(0.5, 2.0, 10, 20);
154 glEndList();
155
156 glEnable(GL_LIGHTING);
157 glEnable(GL_LIGHT0);
158
159 glEnable(GL_DEPTH_TEST);
160 glEnable(GL_CULL_FACE);
161 }
162
163
164 int main( int argc, char *argv[] )
165 {
166 #ifndef _WIN32
167 printf("NOTE: if you've got 3Dfx VooDoo hardware you must run this");
168 printf(" program as root.\n\n");
169 printf("Move the mouse. Press ESC to exit.\n\n");
170 #endif
171
172 /* Tell Mesa GLX to use 3Dfx driver in fullscreen mode. */
173 putenv("MESA_GLX_FX=fullscreen");
174
175 /* Disable 3Dfx Glide splash screen */
176 putenv("FX_GLIDE_NO_SPLASH=");
177
178 /* Give an initial size and position so user doesn't have to place window */
179 glutInitWindowPosition(0, 0);
180 glutInitWindowSize(WIDTH, HEIGHT);
181 glutInit( &argc, argv );
182
183 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
184
185 Window = glutCreateWindow(argv[0]);
186 if (!Window) {
187 printf("Error, couldn't open window\n");
188 exit(1);
189 }
190
191 /*
192 * Want the X window to fill the screen so that we don't have to
193 * worry about losing the mouse input focus.
194 * Note that we won't actually see the X window since we never draw
195 * to it, hence, the original X screen's contents aren't disturbed.
196 */
197 glutFullScreen();
198
199 Init();
200
201 glutReshapeFunc( Reshape );
202 glutKeyboardFunc( Key );
203 glutSpecialFunc( SpecialKey );
204 glutDisplayFunc( Display );
205 glutPassiveMotionFunc( MouseMove );
206
207 glutMainLoop();
208 return 0;
209 }