1 /* $Id: glutfx.c,v 1.1 1999/08/19 00:55:40 jtg Exp $ */
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
9 * easy setup and input event handling with GLUT
11 * automatically set MESA environment variables
12 * don't lose mouse input focus
14 * Brian Paul This file is in the public domain.
19 * Revision 1.1 1999/08/19 00:55:40 jtg
22 * Revision 3.2 1999/03/28 18:18:33 brianp
25 * Revision 3.1 1998/06/29 02:37:30 brianp
26 * minor changes for Windows (Ted Jump)
28 * Revision 3.0 1998/02/14 18:42:29 brianp
44 static int Window
= 0;
45 static int ScreenWidth
, ScreenHeight
;
46 static GLuint Torus
= 0;
47 static GLfloat Xrot
= 0.0, Yrot
= 0.0;
51 static void Display( void )
53 static GLfloat blue
[4] = {0.2, 0.2, 1.0, 1.0};
54 static GLfloat red
[4] = {1.0, 0.2, 0.2, 1.0};
55 static GLfloat green
[4] = {0.2, 1.0, 0.2, 1.0};
57 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
60 glRotatef(Xrot
, 1, 0, 0);
61 glRotatef(Yrot
, 0, 1, 0);
63 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, blue
);
66 glRotatef(90.0, 1, 0, 0);
67 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, red
);
70 glRotatef(90.0, 0, 1, 0);
71 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, green
);
80 static void Reshape( int width
, int height
)
82 float ratio
= (float) width
/ (float) height
;
85 ScreenHeight
= height
;
88 * The 3Dfx driver is limited to 640 x 480 but the X window may be larger.
96 glViewport( 0, 0, width
, height
);
97 glMatrixMode( GL_PROJECTION
);
99 glFrustum( -ratio
, ratio
, -1.0, 1.0, 5.0, 30.0 );
100 glMatrixMode( GL_MODELVIEW
);
102 glTranslatef( 0.0, 0.0, -20.0 );
106 static void Key( unsigned char key
, int x
, int y
)
112 glutDestroyWindow(Window
);
120 static void SpecialKey( int key
, int x
, int y
)
138 static void MouseMove( int x
, int y
)
140 Xrot
= y
- ScreenWidth
/ 2;
141 Yrot
= x
- ScreenHeight
/ 2;
146 static void Init( void )
148 Torus
= glGenLists(1);
149 glNewList(Torus
, GL_COMPILE
);
150 glutSolidTorus(0.5, 2.0, 10, 20);
153 glEnable(GL_LIGHTING
);
156 glEnable(GL_DEPTH_TEST
);
157 glEnable(GL_CULL_FACE
);
161 int main( int argc
, char *argv
[] )
164 printf("NOTE: if you've got 3Dfx VooDoo hardware you must run this");
165 printf(" program as root.\n\n");
166 printf("Move the mouse. Press ESC to exit.\n\n");
170 /* Tell Mesa GLX to use 3Dfx driver in fullscreen mode. */
171 putenv("MESA_GLX_FX=fullscreen");
173 /* Disable 3Dfx Glide splash screen */
174 putenv("FX_GLIDE_NO_SPLASH=");
176 /* Give an initial size and position so user doesn't have to place window */
177 glutInitWindowPosition(0, 0);
178 glutInitWindowSize(WIDTH
, HEIGHT
);
179 glutInit( &argc
, argv
);
181 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
183 Window
= glutCreateWindow(argv
[0]);
185 printf("Error, couldn't open window\n");
190 * Want the X window to fill the screen so that we don't have to
191 * worry about losing the mouse input focus.
192 * Note that we won't actually see the X window since we never draw
193 * to it, hence, the original X screen's contents aren't disturbed.
199 glutReshapeFunc( Reshape
);
200 glutKeyboardFunc( Key
);
201 glutSpecialFunc( SpecialKey
);
202 glutDisplayFunc( Display
);
203 glutPassiveMotionFunc( MouseMove
);