demos: add missing binaries to .gitignore
[mesa-demos.git] / src / tests / glutfx.c
blob9aae401a0d62c5009abc8acab4b8a600dad1090b
2 /*
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
5 * using Glide.
7 * Goals:
8 * easy setup and input event handling with GLUT
9 * use 3Dfx hardware
10 * automatically set MESA environment variables
11 * don't lose mouse input focus
13 * Brian Paul This file is in the public domain.
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <math.h>
20 #include "glut_wrap.h"
23 #define WIDTH 640
24 #define HEIGHT 480
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 );
42 glPushMatrix();
43 glRotatef(Xrot, 1, 0, 0);
44 glRotatef(Yrot, 0, 1, 0);
46 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, blue);
47 glCallList(Torus);
49 glRotatef(90.0, 1, 0, 0);
50 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red);
51 glCallList(Torus);
53 glRotatef(90.0, 0, 1, 0);
54 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, green);
55 glCallList(Torus);
57 glPopMatrix();
59 glutSwapBuffers();
63 static void Reshape( int width, int height )
65 float ratio = (float) width / (float) height;
67 ScreenWidth = width;
68 ScreenHeight = height;
71 * The 3Dfx driver is limited to 640 x 480 but the X window may be larger.
72 * Enforce that here.
74 if (width > WIDTH)
75 width = WIDTH;
76 if (height > HEIGHT)
77 height = HEIGHT;
79 glViewport( 0, 0, width, height );
80 glMatrixMode( GL_PROJECTION );
81 glLoadIdentity();
82 glFrustum( -ratio, ratio, -1.0, 1.0, 5.0, 30.0 );
83 glMatrixMode( GL_MODELVIEW );
84 glLoadIdentity();
85 glTranslatef( 0.0, 0.0, -20.0 );
89 static void Key( unsigned char key, int x, int y )
91 (void) x;
92 (void) y;
93 switch (key) {
94 case 27:
95 glutDestroyWindow(Window);
96 exit(0);
97 break;
99 glutPostRedisplay();
103 static void SpecialKey( int key, int x, int y )
105 (void) x;
106 (void) y;
107 switch (key) {
108 case GLUT_KEY_UP:
109 break;
110 case GLUT_KEY_DOWN:
111 break;
112 case GLUT_KEY_LEFT:
113 break;
114 case GLUT_KEY_RIGHT:
115 break;
117 glutPostRedisplay();
121 static void MouseMove( int x, int y )
123 Xrot = y - ScreenWidth / 2;
124 Yrot = x - ScreenHeight / 2;
125 glutPostRedisplay();
129 static void Init( void )
131 Torus = glGenLists(1);
132 glNewList(Torus, GL_COMPILE);
133 glutSolidTorus(0.5, 2.0, 10, 20);
134 glEndList();
136 glEnable(GL_LIGHTING);
137 glEnable(GL_LIGHT0);
139 glEnable(GL_DEPTH_TEST);
140 glEnable(GL_CULL_FACE);
144 int main( int argc, char *argv[] )
146 #ifndef _WIN32
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");
150 #endif
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]);
166 if (!Window) {
167 printf("Error, couldn't open window\n");
168 exit(1);
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.
177 glutFullScreen();
179 Init();
181 glutReshapeFunc( Reshape );
182 glutKeyboardFunc( Key );
183 glutSpecialFunc( SpecialKey );
184 glutDisplayFunc( Display );
185 glutPassiveMotionFunc( MouseMove );
187 glutMainLoop();
188 return 0;