Clone of mesa.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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