Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

glutskel.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /* $Id: glutskel.c,v 1.1 1999/08/19 00:55:42 jtg Exp $ */
  2. /*
  3. * A skeleton/template GLUT program
  4. *
  5. * Written by Brian Paul and in the public domain.
  6. */
  7. /*
  8. * $Log: glutskel.c,v $
  9. * Revision 1.1 1999/08/19 00:55:42 jtg
  10. * Initial revision
  11. *
  12. * Revision 1.2 1998/11/07 14:20:14 brianp
  13. * added simple rotation, animation of cube
  14. *
  15. * Revision 1.1 1998/11/07 14:14:37 brianp
  16. * Initial revision
  17. *
  18. */
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <math.h>
  22. #include <GL/glut.h>
  23. static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
  24. static GLboolean Anim = GL_FALSE;
  25. static void Idle( void )
  26. {
  27. Xrot += 3.0;
  28. Yrot += 4.0;
  29. Zrot += 2.0;
  30. glutPostRedisplay();
  31. }
  32. static void Display( void )
  33. {
  34. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  35. glPushMatrix();
  36. glRotatef(Xrot, 1, 0, 0);
  37. glRotatef(Yrot, 0, 1, 0);
  38. glRotatef(Zrot, 0, 0, 1);
  39. glutSolidCube(2.0);
  40. glPopMatrix();
  41. glutSwapBuffers();
  42. }
  43. static void Reshape( int width, int height )
  44. {
  45. glViewport( 0, 0, width, height );
  46. glMatrixMode( GL_PROJECTION );
  47. glLoadIdentity();
  48. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  49. glMatrixMode( GL_MODELVIEW );
  50. glLoadIdentity();
  51. glTranslatef( 0.0, 0.0, -15.0 );
  52. }
  53. static void Key( unsigned char key, int x, int y )
  54. {
  55. const GLfloat step = 3.0;
  56. (void) x;
  57. (void) y;
  58. switch (key) {
  59. case 'a':
  60. Anim = !Anim;
  61. if (Anim)
  62. glutIdleFunc(Idle);
  63. else
  64. glutIdleFunc(NULL);
  65. break;
  66. case 'z':
  67. Zrot -= step;
  68. break;
  69. case 'Z':
  70. Zrot += step;
  71. break;
  72. case 27:
  73. exit(0);
  74. break;
  75. }
  76. glutPostRedisplay();
  77. }
  78. static void SpecialKey( int key, int x, int y )
  79. {
  80. const GLfloat step = 3.0;
  81. (void) x;
  82. (void) y;
  83. switch (key) {
  84. case GLUT_KEY_UP:
  85. Xrot -= step;
  86. break;
  87. case GLUT_KEY_DOWN:
  88. Xrot += step;
  89. break;
  90. case GLUT_KEY_LEFT:
  91. Yrot -= step;
  92. break;
  93. case GLUT_KEY_RIGHT:
  94. Yrot += step;
  95. break;
  96. }
  97. glutPostRedisplay();
  98. }
  99. static void Init( void )
  100. {
  101. /* setup lighting, etc */
  102. glEnable(GL_DEPTH_TEST);
  103. glEnable(GL_LIGHTING);
  104. glEnable(GL_LIGHT0);
  105. }
  106. int main( int argc, char *argv[] )
  107. {
  108. glutInit( &argc, argv );
  109. glutInitWindowPosition( 0, 0 );
  110. glutInitWindowSize( 400, 400 );
  111. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  112. glutCreateWindow(argv[0]);
  113. glutReshapeFunc( Reshape );
  114. glutKeyboardFunc( Key );
  115. glutSpecialFunc( SpecialKey );
  116. glutDisplayFunc( Display );
  117. Init();
  118. glutMainLoop();
  119. return 0;
  120. }