Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glutfx.c 4.4KB

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