rev |
line source |
nuclear@0
|
1 #include <stdio.h>
|
nuclear@0
|
2 #include <stdlib.h>
|
nuclear@2
|
3 #include <assert.h>
|
nuclear@0
|
4 #ifndef __APPLE__
|
nuclear@0
|
5 #include <GL/glut.h>
|
nuclear@0
|
6 #else
|
nuclear@0
|
7 #include <GLUT/glut.h>
|
nuclear@0
|
8 #endif
|
nuclear@0
|
9 #include "imtk.h"
|
nuclear@0
|
10
|
nuclear@0
|
11 void disp(void);
|
nuclear@1
|
12 void gui(void);
|
nuclear@0
|
13 void reshape(int x, int y);
|
nuclear@0
|
14 void keyb(unsigned char key, int x, int y);
|
nuclear@0
|
15 void keyb_up(unsigned char key, int x, int y);
|
nuclear@0
|
16 void skeyb(int key, int x, int y);
|
nuclear@0
|
17 void skeyb_up(int key, int x, int y);
|
nuclear@0
|
18 void mouse(int bn, int state, int x, int y);
|
nuclear@0
|
19 void motion(int x, int y);
|
nuclear@0
|
20
|
nuclear@2
|
21 int xsz, ysz;
|
nuclear@3
|
22 float angle;
|
nuclear@4
|
23 int objsel;
|
nuclear@0
|
24
|
nuclear@0
|
25 int main(int argc, char **argv)
|
nuclear@0
|
26 {
|
nuclear@2
|
27 float lpos[] = {-1, 1, 1, 0};
|
nuclear@2
|
28 float white[] = {1, 1, 1, 1};
|
nuclear@2
|
29 float color[] = {0.9, 0.8, 0.73, 1};
|
nuclear@2
|
30
|
nuclear@0
|
31 glutInitWindowSize(800, 600);
|
nuclear@0
|
32 glutInit(&argc, argv);
|
nuclear@0
|
33 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
|
nuclear@0
|
34 glutCreateWindow("imgui test");
|
nuclear@0
|
35
|
nuclear@0
|
36 glutDisplayFunc(disp);
|
nuclear@0
|
37 glutReshapeFunc(reshape);
|
nuclear@0
|
38 glutKeyboardFunc(keyb);
|
nuclear@0
|
39 glutKeyboardUpFunc(keyb_up);
|
nuclear@0
|
40 glutSpecialFunc(skeyb);
|
nuclear@0
|
41 glutSpecialUpFunc(skeyb_up);
|
nuclear@0
|
42 glutMouseFunc(mouse);
|
nuclear@0
|
43 glutMotionFunc(motion);
|
nuclear@0
|
44 glutPassiveMotionFunc(motion);
|
nuclear@0
|
45
|
nuclear@2
|
46 glEnable(GL_DEPTH_TEST);
|
nuclear@2
|
47 glEnable(GL_CULL_FACE);
|
nuclear@2
|
48 glEnable(GL_LIGHTING);
|
nuclear@2
|
49 glEnable(GL_LIGHT0);
|
nuclear@2
|
50 glLightfv(GL_LIGHT0, GL_POSITION, lpos);
|
nuclear@2
|
51
|
nuclear@2
|
52 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
|
nuclear@2
|
53 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
|
nuclear@2
|
54 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60.0);
|
nuclear@2
|
55
|
nuclear@0
|
56 glutMainLoop();
|
nuclear@0
|
57 return 0;
|
nuclear@0
|
58 }
|
nuclear@0
|
59
|
nuclear@0
|
60 void disp(void)
|
nuclear@0
|
61 {
|
nuclear@0
|
62 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
nuclear@0
|
63
|
nuclear@5
|
64 glPushAttrib(GL_ENABLE_BIT);
|
nuclear@5
|
65 glDisable(GL_LIGHTING);
|
nuclear@5
|
66 glDisable(GL_DEPTH_TEST);
|
nuclear@2
|
67
|
nuclear@2
|
68 glMatrixMode(GL_MODELVIEW);
|
nuclear@2
|
69 glLoadIdentity();
|
nuclear@5
|
70
|
nuclear@5
|
71 glMatrixMode(GL_PROJECTION);
|
nuclear@5
|
72 glPushMatrix();
|
nuclear@5
|
73 glLoadIdentity();
|
nuclear@5
|
74
|
nuclear@5
|
75 glBegin(GL_QUADS);
|
nuclear@5
|
76 glColor3f(0.2, 0.3, 0.7);
|
nuclear@5
|
77 glVertex2f(1, 1);
|
nuclear@5
|
78 glVertex2f(-1, 1);
|
nuclear@5
|
79 glColor3f(0.7, 0.3, 0.2);
|
nuclear@5
|
80 glVertex2f(-1, -1);
|
nuclear@5
|
81 glVertex2f(1, -1);
|
nuclear@5
|
82 glEnd();
|
nuclear@5
|
83
|
nuclear@5
|
84 glPopMatrix();
|
nuclear@5
|
85 glMatrixMode(GL_MODELVIEW);
|
nuclear@5
|
86
|
nuclear@5
|
87 glPopAttrib();
|
nuclear@5
|
88
|
nuclear@2
|
89 glTranslatef(0, 0, -8);
|
nuclear@2
|
90 glRotatef(25, 1, 0, 0);
|
nuclear@3
|
91 glRotatef(angle, 0, 1, 0);
|
nuclear@2
|
92
|
nuclear@4
|
93 switch(objsel) {
|
nuclear@4
|
94 case 0:
|
nuclear@4
|
95 glFrontFace(GL_CW);
|
nuclear@4
|
96 glutSolidTeapot(1.0);
|
nuclear@4
|
97 glFrontFace(GL_CCW);
|
nuclear@4
|
98 break;
|
nuclear@4
|
99
|
nuclear@4
|
100 case 1:
|
nuclear@4
|
101 glutSolidTorus(0.5, 1, 12, 24);
|
nuclear@4
|
102 break;
|
nuclear@4
|
103
|
nuclear@4
|
104 case 2:
|
nuclear@4
|
105 glutSolidSphere(1.0, 24, 12);
|
nuclear@4
|
106 break;
|
nuclear@4
|
107
|
nuclear@4
|
108 default:
|
nuclear@4
|
109 break;
|
nuclear@4
|
110 }
|
nuclear@2
|
111
|
nuclear@2
|
112
|
nuclear@1
|
113 gui();
|
nuclear@1
|
114
|
nuclear@1
|
115 glutSwapBuffers();
|
nuclear@2
|
116 assert(glGetError() == GL_NO_ERROR);
|
nuclear@1
|
117 }
|
nuclear@1
|
118
|
nuclear@1
|
119 void gui(void)
|
nuclear@1
|
120 {
|
nuclear@8
|
121 static int bnshow = 1;
|
nuclear@2
|
122 static char textbuf[256];
|
nuclear@2
|
123 static char textbuf2[256];
|
nuclear@3
|
124 static float val;
|
nuclear@4
|
125 static int prev_sel;
|
nuclear@4
|
126 char *itemlist;
|
nuclear@1
|
127
|
nuclear@0
|
128 imtk_begin();
|
nuclear@0
|
129
|
nuclear@2
|
130 if(imtk_button(IMUID, "red", 30, 50)) {
|
nuclear@2
|
131 float color[] = {1, 0.4, 0.3, 1};
|
nuclear@2
|
132 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
|
nuclear@2
|
133 glutPostRedisplay();
|
nuclear@0
|
134 }
|
nuclear@4
|
135 if(imtk_button(IMUID, "blue", 30, 80)) {
|
nuclear@2
|
136 float color[] = {0.3, 0.4, 1, 1};
|
nuclear@2
|
137 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
|
nuclear@2
|
138 glutPostRedisplay();
|
nuclear@1
|
139 }
|
nuclear@1
|
140
|
nuclear@4
|
141 itemlist = imtk_create_list("teapot", "torus", "sphere", NULL);
|
nuclear@4
|
142 if((objsel = imtk_listbox(IMUID, itemlist, prev_sel, 30, 120)) != prev_sel) {
|
nuclear@4
|
143 prev_sel = objsel;
|
nuclear@4
|
144 glutPostRedisplay();
|
nuclear@4
|
145 }
|
nuclear@4
|
146 imtk_free_list(itemlist);
|
nuclear@4
|
147
|
nuclear@2
|
148 imtk_textbox(IMUID, textbuf, sizeof textbuf, 30, 200);
|
nuclear@2
|
149 imtk_textbox(IMUID, textbuf2, sizeof textbuf2, 30, 250);
|
nuclear@2
|
150
|
nuclear@2
|
151 if((bnshow = imtk_checkbox(IMUID, "show hidden button", 30, 300, bnshow))) {
|
nuclear@2
|
152 if(imtk_button(IMUID, "yellow", 50, 340)) {
|
nuclear@2
|
153 float color[] = {0.8, 0.75, 0.3, 1};
|
nuclear@2
|
154 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
|
nuclear@2
|
155 glutPostRedisplay();
|
nuclear@1
|
156 }
|
nuclear@1
|
157 }
|
nuclear@0
|
158
|
nuclear@3
|
159 val = imtk_slider(IMUID, angle, 0.0, 360.0, 30, 390);
|
nuclear@3
|
160 if(val != angle) {
|
nuclear@3
|
161 angle = val;
|
nuclear@3
|
162 glutPostRedisplay();
|
nuclear@3
|
163 }
|
nuclear@3
|
164
|
nuclear@3
|
165 imtk_progress(IMUID, val / 360.0, 30, 420);
|
nuclear@3
|
166
|
nuclear@2
|
167 if(imtk_button(IMUID, "Quit", 30, 500)) {
|
nuclear@2
|
168 exit(0);
|
nuclear@2
|
169 }
|
nuclear@2
|
170
|
nuclear@0
|
171 imtk_end();
|
nuclear@0
|
172 }
|
nuclear@0
|
173
|
nuclear@0
|
174 void reshape(int x, int y)
|
nuclear@0
|
175 {
|
nuclear@2
|
176 xsz = x;
|
nuclear@2
|
177 ysz = y;
|
nuclear@2
|
178
|
nuclear@0
|
179 glViewport(0, 0, x, y);
|
nuclear@5
|
180 imtk_inp_reshape(x, y);
|
nuclear@5
|
181
|
nuclear@5
|
182 glMatrixMode(GL_PROJECTION);
|
nuclear@5
|
183 glLoadIdentity();
|
nuclear@5
|
184 gluPerspective(45.0, (float)x / (float)y, 1.0, 1000.0);
|
nuclear@0
|
185 }
|
nuclear@0
|
186
|
nuclear@0
|
187 void keyb(unsigned char key, int x, int y)
|
nuclear@0
|
188 {
|
nuclear@0
|
189 switch(key) {
|
nuclear@0
|
190 case 27:
|
nuclear@0
|
191 exit(0);
|
nuclear@0
|
192
|
nuclear@0
|
193 default:
|
nuclear@0
|
194 break;
|
nuclear@0
|
195 }
|
nuclear@0
|
196
|
nuclear@0
|
197 imtk_inp_key(key, IMTK_DOWN);
|
nuclear@0
|
198 }
|
nuclear@0
|
199
|
nuclear@0
|
200 void keyb_up(unsigned char key, int x, int y)
|
nuclear@0
|
201 {
|
nuclear@0
|
202 imtk_inp_key(key, IMTK_UP);
|
nuclear@0
|
203 }
|
nuclear@0
|
204
|
nuclear@0
|
205 void skeyb(int key, int x, int y)
|
nuclear@0
|
206 {
|
nuclear@0
|
207 imtk_inp_key(key, IMTK_DOWN);
|
nuclear@0
|
208 }
|
nuclear@0
|
209
|
nuclear@0
|
210 void skeyb_up(int key, int x, int y)
|
nuclear@0
|
211 {
|
nuclear@0
|
212 imtk_inp_key(key, IMTK_UP);
|
nuclear@0
|
213 }
|
nuclear@0
|
214
|
nuclear@0
|
215 void mouse(int bn, int state, int x, int y)
|
nuclear@0
|
216 {
|
nuclear@0
|
217 imtk_inp_mouse(bn, state == GLUT_DOWN ? IMTK_DOWN : IMTK_UP);
|
nuclear@0
|
218 }
|
nuclear@0
|
219
|
nuclear@0
|
220 void motion(int x, int y)
|
nuclear@0
|
221 {
|
nuclear@0
|
222 imtk_inp_motion(x, y);
|
nuclear@0
|
223 }
|