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