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