6b9d9faf4e9c8726dd25765bf841ce93e6d75ac5
1 /* $Id: glutfx.c,v 1.2 2000/06/27 17:04:43 brianp 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.2 2000/06/27 17:04:43 brianp
20 * fixed compiler warnings
22 * Revision 1.1.1.1 1999/08/19 00:55:40 jtg
25 * Revision 3.2 1999/03/28 18:18:33 brianp
28 * Revision 3.1 1998/06/29 02:37:30 brianp
29 * minor changes for Windows (Ted Jump)
31 * Revision 3.0 1998/02/14 18:42:29 brianp
47 static int Window
= 0;
48 static int ScreenWidth
, ScreenHeight
;
49 static GLuint Torus
= 0;
50 static GLfloat Xrot
= 0.0, Yrot
= 0.0;
54 static void Display( void )
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};
60 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
63 glRotatef(Xrot
, 1, 0, 0);
64 glRotatef(Yrot
, 0, 1, 0);
66 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, blue
);
69 glRotatef(90.0, 1, 0, 0);
70 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, red
);
73 glRotatef(90.0, 0, 1, 0);
74 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, green
);
83 static void Reshape( int width
, int height
)
85 float ratio
= (float) width
/ (float) height
;
88 ScreenHeight
= height
;
91 * The 3Dfx driver is limited to 640 x 480 but the X window may be larger.
99 glViewport( 0, 0, width
, height
);
100 glMatrixMode( GL_PROJECTION
);
102 glFrustum( -ratio
, ratio
, -1.0, 1.0, 5.0, 30.0 );
103 glMatrixMode( GL_MODELVIEW
);
105 glTranslatef( 0.0, 0.0, -20.0 );
109 static void Key( unsigned char key
, int x
, int y
)
115 glutDestroyWindow(Window
);
123 static void SpecialKey( int key
, int x
, int y
)
141 static void MouseMove( int x
, int y
)
143 Xrot
= y
- ScreenWidth
/ 2;
144 Yrot
= x
- ScreenHeight
/ 2;
149 static void Init( void )
151 Torus
= glGenLists(1);
152 glNewList(Torus
, GL_COMPILE
);
153 glutSolidTorus(0.5, 2.0, 10, 20);
156 glEnable(GL_LIGHTING
);
159 glEnable(GL_DEPTH_TEST
);
160 glEnable(GL_CULL_FACE
);
164 int main( int argc
, char *argv
[] )
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");
172 /* Tell Mesa GLX to use 3Dfx driver in fullscreen mode. */
173 putenv("MESA_GLX_FX=fullscreen");
175 /* Disable 3Dfx Glide splash screen */
176 putenv("FX_GLIDE_NO_SPLASH=");
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
);
183 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
185 Window
= glutCreateWindow(argv
[0]);
187 printf("Error, couldn't open window\n");
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.
201 glutReshapeFunc( Reshape
);
202 glutKeyboardFunc( Key
);
203 glutSpecialFunc( SpecialKey
);
204 glutDisplayFunc( Display
);
205 glutPassiveMotionFunc( MouseMove
);