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.

glutskel.c 2.3KB

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