Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/doc/program_examples/openGL/cube.c @ 1803

Last change on this file since 1803 was 1803, checked in by patrick, 20 years ago

doc update

File size: 1.4 KB
Line 
1
2
3#include <GL/glut.h>
4
5#include <stdio.h>
6#include <stdlib.h>
7
8
9static float alpha = 0;
10
11void init(void) {
12
13  glClearColor(0.0, 0.0, 0.0, 0.0);
14  glShadeModel(GL_FLAT);
15}
16
17
18void display(void) {
19
20  glClear(GL_COLOR_BUFFER_BIT);
21  glColor3f(1.0, 1.0, 1.0);
22  glLoadIdentity();
23 
24  gluLookAt(5*cos(alpha), 5*sin(alpha), 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
25  glScalef(1.0, 2.0, 1.0);
26  glutWireCube(1.0);
27  glFlush();
28}
29
30
31void reshape(int w, int h) {
32
33  glViewport(0, 0, (GLsizei) w, (GLsizei)h);
34  glMatrixMode(GL_PROJECTION);
35  glLoadIdentity();
36  glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
37  glMatrixMode(GL_MODELVIEW);
38}
39
40
41void spinDisplay( void ) {
42
43  alpha = alpha + 0.01;
44  if (alpha > 360)
45    alpha = 0;
46  glutPostRedisplay();
47}
48
49
50void mouse( int button, int state, int x, int y ) {
51
52  switch( button ) {
53  case GLUT_LEFT_BUTTON:
54    if (state == GLUT_DOWN) {
55      glutIdleFunc(spinDisplay);
56    }
57    break;
58  case GLUT_RIGHT_BUTTON:
59    if (state == GLUT_DOWN) {
60      glutIdleFunc(NULL);
61    }
62    break;
63  default:
64    break;
65  }
66}
67
68
69
70int main(int argc, char** argv) {
71
72  glutInit(&argc, argv);
73  glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
74  glutInitWindowSize(500, 500);
75  glutInitWindowPosition(100, 100);
76  glutCreateWindow(argv[0]);
77  init();
78  glutDisplayFunc(display);
79  glutReshapeFunc(reshape);
80  glutMouseFunc(mouse);
81  glutMainLoop();
82
83  return 0;
84}
85
86
87//EOF
Note: See TracBrowser for help on using the repository browser.