12 void reg_whitted(void);
14 int win_width, win_height;
18 struct dtx_font *fnt_ui;
21 static int reshape_pending;
22 static unsigned int sdr_gamma;
28 if(init_opengl() == -1) {
32 glEnable(GL_DEPTH_TEST);
33 glEnable(GL_CULL_FACE);
35 glEnable(GL_FRAMEBUFFER_SRGB);
38 glEnable(GL_MULTISAMPLE);
47 if(!(fnt_ui = dtx_open_font_glyphmap("data/ui.glyphmap"))) {
48 fprintf(stderr, "failed to open ui font\n");
51 fnt_ui_size = dtx_get_glyphmap_ptsize(dtx_get_glyphmap(fnt_ui, 0));
52 dtx_prepare_range(fnt_ui, fnt_ui_size, 32, 127);
56 if(!(sdr_gamma = create_program_load("sdr/post.v.glsl", "sdr/gamma.p.glsl"))) {
57 fprintf(stderr, "Warning: failed to load the gamma correction shader\n");
62 for(i=0; i<num_parts; i++) {
63 if(parts[i]->init() == -1) {
64 fprintf(stderr, "part %s init failed\n", parts[i]->name);
69 switch_part(parts[0]);
73 void demo_cleanup(void)
78 glDeleteProgram(sdr_gamma);
82 for(i=0; i<num_parts; i++) {
86 dtx_close_font(fnt_ui);
89 void demo_display(void)
94 post_reshape(win_width, win_height);
98 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
100 if(!cur_part) return;
102 part_time = time_msec - cur_part->start_time;
103 if(part_time < cur_part->in_time) {
104 float t = (float)part_time / cur_part->in_time;
107 long prev_part_time = time_msec - prev_part->start_time;
108 if(prev_part->draw_out) {
109 prev_part->draw_out(prev_part_time, t);
111 prev_part->draw(prev_part_time);
115 if(cur_part->draw_in) {
116 cur_part->draw_in(part_time, t);
118 cur_part->draw(part_time);
122 cur_part->draw(part_time);
125 /* no-srgb gamma correction fallback */
127 glBindTexture(GL_TEXTURE_2D, post_fbtex[0].id);
128 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_width, win_height);
130 glUseProgram(sdr_gamma);
131 overlay_tex(post_fbtex, 1.0);
135 static long frames, prev_upd, fps;
140 dt = time_msec - prev_upd;
142 fps = (frames * 1000 << 8 + 128) / dt;
144 prev_upd = time_msec;
147 print_text(win_width - 80, 20, 1.0, 0.8, 0.1, "fps: %ld.%ld", fps >> 8, ((fps & 0xff) * 10) >> 8);
153 void demo_reshape(int x, int y)
159 win_aspect = (float)x / (float)y;
161 glViewport(0, 0, x, y);
163 glMatrixMode(GL_PROJECTION);
165 gluPerspective(50.0, win_aspect, 0.5, 500.0);
167 imtk_set_viewport(x, y);
170 void demo_keyboard(int key, int st)
172 if(st && key == 27) {
177 if(cur_part && cur_part->keyboard) {
178 cur_part->keyboard(key, st);
183 void demo_mbutton(int bn, int st, int x, int y)
185 if(cur_part && cur_part->mbutton) {
186 cur_part->mbutton(bn, st, x, y);
190 void demo_mmotion(int x, int y)
192 if(cur_part && cur_part->mmotion) {
193 cur_part->mmotion(x, y);
197 void demo_sball_motion(int x, int y, int z)
201 void demo_sball_rotate(int x, int y, int z)
205 void demo_sball_button(int bn, int st)