Clone of mesa.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

glutfx.c 4.4KB

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