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@0
|
23
|
nuclear@0
|
24 int main(int argc, char **argv)
|
nuclear@0
|
25 {
|
nuclear@2
|
26 float lpos[] = {-1, 1, 1, 0};
|
nuclear@2
|
27 float white[] = {1, 1, 1, 1};
|
nuclear@2
|
28 float color[] = {0.9, 0.8, 0.73, 1};
|
nuclear@2
|
29
|
nuclear@0
|
30 glutInitWindowSize(800, 600);
|
nuclear@0
|
31 glutInit(&argc, argv);
|
nuclear@0
|
32 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
|
nuclear@0
|
33 glutCreateWindow("imgui test");
|
nuclear@0
|
34
|
nuclear@0
|
35 glutDisplayFunc(disp);
|
nuclear@0
|
36 glutReshapeFunc(reshape);
|
nuclear@0
|
37 glutKeyboardFunc(keyb);
|
nuclear@0
|
38 glutKeyboardUpFunc(keyb_up);
|
nuclear@0
|
39 glutSpecialFunc(skeyb);
|
nuclear@0
|
40 glutSpecialUpFunc(skeyb_up);
|
nuclear@0
|
41 glutMouseFunc(mouse);
|
nuclear@0
|
42 glutMotionFunc(motion);
|
nuclear@0
|
43 glutPassiveMotionFunc(motion);
|
nuclear@0
|
44
|
nuclear@2
|
45 glEnable(GL_DEPTH_TEST);
|
nuclear@2
|
46 glEnable(GL_CULL_FACE);
|
nuclear@2
|
47 glEnable(GL_LIGHTING);
|
nuclear@2
|
48 glEnable(GL_LIGHT0);
|
nuclear@2
|
49 glLightfv(GL_LIGHT0, GL_POSITION, lpos);
|
nuclear@2
|
50
|
nuclear@2
|
51 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
|
nuclear@2
|
52 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
|
nuclear@2
|
53 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60.0);
|
nuclear@2
|
54
|
nuclear@0
|
55 glutMainLoop();
|
nuclear@0
|
56 return 0;
|
nuclear@0
|
57 }
|
nuclear@0
|
58
|
nuclear@0
|
59 void disp(void)
|
nuclear@0
|
60 {
|
nuclear@0
|
61 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
nuclear@0
|
62
|
nuclear@2
|
63 glViewport(200, 0, xsz - 200, ysz);
|
nuclear@2
|
64
|
nuclear@2
|
65 glMatrixMode(GL_PROJECTION);
|
nuclear@2
|
66 glLoadIdentity();
|
nuclear@2
|
67 gluPerspective(45.0, (float)(xsz - 200) / (float)ysz, 1.0, 1000.0);
|
nuclear@2
|
68
|
nuclear@2
|
69 glMatrixMode(GL_MODELVIEW);
|
nuclear@2
|
70 glLoadIdentity();
|
nuclear@2
|
71 glTranslatef(0, 0, -8);
|
nuclear@2
|
72 glRotatef(25, 1, 0, 0);
|
nuclear@3
|
73 glRotatef(angle, 0, 1, 0);
|
nuclear@2
|
74
|
nuclear@2
|
75 glFrontFace(GL_CW);
|
nuclear@2
|
76 glutSolidTeapot(1.0);
|
nuclear@2
|
77 glFrontFace(GL_CCW);
|
nuclear@2
|
78
|
nuclear@2
|
79
|
nuclear@2
|
80 glViewport(0, 0, 200, ysz);
|
nuclear@2
|
81 imtk_inp_reshape(200, ysz);
|
nuclear@2
|
82
|
nuclear@1
|
83 gui();
|
nuclear@1
|
84
|
nuclear@1
|
85 glutSwapBuffers();
|
nuclear@2
|
86 assert(glGetError() == GL_NO_ERROR);
|
nuclear@1
|
87 }
|
nuclear@1
|
88
|
nuclear@1
|
89 void gui(void)
|
nuclear@1
|
90 {
|
nuclear@1
|
91 static int bnshow;
|
nuclear@2
|
92 static char textbuf[256];
|
nuclear@2
|
93 static char textbuf2[256];
|
nuclear@3
|
94 static float val;
|
nuclear@1
|
95
|
nuclear@0
|
96 imtk_begin();
|
nuclear@0
|
97
|
nuclear@2
|
98 glBegin(GL_QUADS);
|
nuclear@2
|
99 glColor3f(0.6, 0.6, 0.6);
|
nuclear@2
|
100 glVertex2f(0, 0);
|
nuclear@2
|
101 glVertex2f(200, 0);
|
nuclear@2
|
102 glVertex2f(200, glutGet(GLUT_WINDOW_HEIGHT));
|
nuclear@2
|
103 glVertex2f(0, glutGet(GLUT_WINDOW_HEIGHT));
|
nuclear@2
|
104 glEnd();
|
nuclear@2
|
105
|
nuclear@2
|
106 if(imtk_button(IMUID, "red", 30, 50)) {
|
nuclear@2
|
107 float color[] = {1, 0.4, 0.3, 1};
|
nuclear@2
|
108 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
|
nuclear@2
|
109 glutPostRedisplay();
|
nuclear@0
|
110 }
|
nuclear@2
|
111 if(imtk_button(IMUID, "blue", 30, 100)) {
|
nuclear@2
|
112 float color[] = {0.3, 0.4, 1, 1};
|
nuclear@2
|
113 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
|
nuclear@2
|
114 glutPostRedisplay();
|
nuclear@1
|
115 }
|
nuclear@1
|
116
|
nuclear@2
|
117 imtk_textbox(IMUID, textbuf, sizeof textbuf, 30, 200);
|
nuclear@2
|
118 imtk_textbox(IMUID, textbuf2, sizeof textbuf2, 30, 250);
|
nuclear@2
|
119
|
nuclear@2
|
120 if((bnshow = imtk_checkbox(IMUID, "show hidden button", 30, 300, bnshow))) {
|
nuclear@2
|
121 if(imtk_button(IMUID, "yellow", 50, 340)) {
|
nuclear@2
|
122 float color[] = {0.8, 0.75, 0.3, 1};
|
nuclear@2
|
123 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color);
|
nuclear@2
|
124 glutPostRedisplay();
|
nuclear@1
|
125 }
|
nuclear@1
|
126 }
|
nuclear@0
|
127
|
nuclear@3
|
128 val = imtk_slider(IMUID, angle, 0.0, 360.0, 30, 390);
|
nuclear@3
|
129 if(val != angle) {
|
nuclear@3
|
130 angle = val;
|
nuclear@3
|
131 glutPostRedisplay();
|
nuclear@3
|
132 }
|
nuclear@3
|
133
|
nuclear@3
|
134 imtk_progress(IMUID, val / 360.0, 30, 420);
|
nuclear@3
|
135
|
nuclear@2
|
136 if(imtk_button(IMUID, "Quit", 30, 500)) {
|
nuclear@2
|
137 exit(0);
|
nuclear@2
|
138 }
|
nuclear@2
|
139
|
nuclear@0
|
140 imtk_end();
|
nuclear@0
|
141 }
|
nuclear@0
|
142
|
nuclear@0
|
143 void reshape(int x, int y)
|
nuclear@0
|
144 {
|
nuclear@2
|
145 xsz = x;
|
nuclear@2
|
146 ysz = y;
|
nuclear@2
|
147
|
nuclear@0
|
148 glViewport(0, 0, x, y);
|
nuclear@0
|
149 }
|
nuclear@0
|
150
|
nuclear@0
|
151 void keyb(unsigned char key, int x, int y)
|
nuclear@0
|
152 {
|
nuclear@0
|
153 switch(key) {
|
nuclear@0
|
154 case 27:
|
nuclear@0
|
155 exit(0);
|
nuclear@0
|
156
|
nuclear@0
|
157 default:
|
nuclear@0
|
158 break;
|
nuclear@0
|
159 }
|
nuclear@0
|
160
|
nuclear@0
|
161 imtk_inp_key(key, IMTK_DOWN);
|
nuclear@0
|
162 }
|
nuclear@0
|
163
|
nuclear@0
|
164 void keyb_up(unsigned char key, int x, int y)
|
nuclear@0
|
165 {
|
nuclear@0
|
166 imtk_inp_key(key, IMTK_UP);
|
nuclear@0
|
167 }
|
nuclear@0
|
168
|
nuclear@0
|
169 void skeyb(int key, int x, int y)
|
nuclear@0
|
170 {
|
nuclear@0
|
171 imtk_inp_key(key, IMTK_DOWN);
|
nuclear@0
|
172 }
|
nuclear@0
|
173
|
nuclear@0
|
174 void skeyb_up(int key, int x, int y)
|
nuclear@0
|
175 {
|
nuclear@0
|
176 imtk_inp_key(key, IMTK_UP);
|
nuclear@0
|
177 }
|
nuclear@0
|
178
|
nuclear@0
|
179 void mouse(int bn, int state, int x, int y)
|
nuclear@0
|
180 {
|
nuclear@0
|
181 imtk_inp_mouse(bn, state == GLUT_DOWN ? IMTK_DOWN : IMTK_UP);
|
nuclear@0
|
182 }
|
nuclear@0
|
183
|
nuclear@0
|
184 void motion(int x, int y)
|
nuclear@0
|
185 {
|
nuclear@0
|
186 imtk_inp_motion(x, y);
|
nuclear@0
|
187 }
|