3 * Example of how one might use GLUT with the 3Dfx driver in full-screen mode.
4 * Note: this only works with X since we're using Mesa's GLX "hack" for
8 * easy setup and input event handling with GLUT
10 * automatically set MESA environment variables
11 * don't lose mouse input focus
13 * Brian Paul This file is in the public domain.
20 #include "glut_wrap.h"
27 static int Window
= 0;
28 static int ScreenWidth
, ScreenHeight
;
29 static GLuint Torus
= 0;
30 static GLfloat Xrot
= 0.0, Yrot
= 0.0;
34 static void Display( void )
36 static GLfloat blue
[4] = {0.2, 0.2, 1.0, 1.0};
37 static GLfloat red
[4] = {1.0, 0.2, 0.2, 1.0};
38 static GLfloat green
[4] = {0.2, 1.0, 0.2, 1.0};
40 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
43 glRotatef(Xrot
, 1, 0, 0);
44 glRotatef(Yrot
, 0, 1, 0);
46 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, blue
);
49 glRotatef(90.0, 1, 0, 0);
50 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, red
);
53 glRotatef(90.0, 0, 1, 0);
54 glMaterialfv(GL_FRONT_AND_BACK
, GL_AMBIENT_AND_DIFFUSE
, green
);
63 static void Reshape( int width
, int height
)
65 float ratio
= (float) width
/ (float) height
;
68 ScreenHeight
= height
;
71 * The 3Dfx driver is limited to 640 x 480 but the X window may be larger.
79 glViewport( 0, 0, width
, height
);
80 glMatrixMode( GL_PROJECTION
);
82 glFrustum( -ratio
, ratio
, -1.0, 1.0, 5.0, 30.0 );
83 glMatrixMode( GL_MODELVIEW
);
85 glTranslatef( 0.0, 0.0, -20.0 );
89 static void Key( unsigned char key
, int x
, int y
)
95 glutDestroyWindow(Window
);
103 static void SpecialKey( int key
, int x
, int y
)
121 static void MouseMove( int x
, int y
)
123 Xrot
= y
- ScreenWidth
/ 2;
124 Yrot
= x
- ScreenHeight
/ 2;
129 static void Init( void )
131 Torus
= glGenLists(1);
132 glNewList(Torus
, GL_COMPILE
);
133 glutSolidTorus(0.5, 2.0, 10, 20);
136 glEnable(GL_LIGHTING
);
139 glEnable(GL_DEPTH_TEST
);
140 glEnable(GL_CULL_FACE
);
144 int main( int argc
, char *argv
[] )
147 printf("NOTE: if you've got 3Dfx VooDoo hardware you must run this");
148 printf(" program as root.\n\n");
149 printf("Move the mouse. Press ESC to exit.\n\n");
152 /* Tell Mesa GLX to use 3Dfx driver in fullscreen mode. */
153 putenv("MESA_GLX_FX=fullscreen");
155 /* Disable 3Dfx Glide splash screen */
156 putenv("FX_GLIDE_NO_SPLASH=");
158 /* Give an initial size and position so user doesn't have to place window */
159 glutInitWindowPosition(0, 0);
160 glutInitWindowSize(WIDTH
, HEIGHT
);
161 glutInit( &argc
, argv
);
163 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
165 Window
= glutCreateWindow(argv
[0]);
167 printf("Error, couldn't open window\n");
172 * Want the X window to fill the screen so that we don't have to
173 * worry about losing the mouse input focus.
174 * Note that we won't actually see the X window since we never draw
175 * to it, hence, the original X screen's contents aren't disturbed.
181 glutReshapeFunc( Reshape
);
182 glutKeyboardFunc( Key
);
183 glutSpecialFunc( SpecialKey
);
184 glutDisplayFunc( Display
);
185 glutPassiveMotionFunc( MouseMove
);