9 void reg_whitted(void);
11 int win_width, win_height;
15 static int reshape_pending;
16 static unsigned int fbtex;
17 static unsigned int sdr_gamma;
23 if(init_opengl() == -1) {
27 glEnable(GL_DEPTH_TEST);
28 glEnable(GL_CULL_FACE);
29 glEnable(GL_FRAMEBUFFER_SRGB);
30 glEnable(GL_MULTISAMPLE);
32 glGenTextures(1, &fbtex);
33 glBindTexture(GL_TEXTURE_2D, fbtex);
34 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
35 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
37 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
40 if(!(sdr_gamma = create_program_load("sdr/gamma.v.glsl", "sdr/gamma.p.glsl"))) {
41 fprintf(stderr, "Warning: failed to load the gamma correction shader\n");
46 for(i=0; i<num_parts; i++) {
47 if(parts[i]->init() == -1) {
48 fprintf(stderr, "part %s init failed\n", parts[i]->name);
53 switch_part(parts[0]);
57 void demo_cleanup(void)
62 glDeleteProgram(sdr_gamma);
65 glDeleteTextures(1, &fbtex);
68 for(i=0; i<num_parts; i++) {
73 void demo_display(void)
79 glBindTexture(GL_TEXTURE_2D, fbtex);
80 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, win_width, win_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
84 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
88 part_time = time_msec - cur_part->start_time;
89 if(part_time < cur_part->in_time) {
90 float t = (float)part_time / cur_part->in_time;
93 long prev_part_time = time_msec - prev_part->start_time;
94 if(prev_part->draw_out) {
95 prev_part->draw_out(prev_part_time, t);
97 prev_part->draw(prev_part_time);
101 if(cur_part->draw_in) {
102 cur_part->draw_in(part_time, t);
104 cur_part->draw(part_time);
108 cur_part->draw(part_time);
111 /* no-srgb gamma correction fallback */
113 glBindTexture(GL_TEXTURE_2D, fbtex);
114 glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, win_width, win_height);
116 glUseProgram(sdr_gamma);
117 overlay(fbtex, win_aspect, 1.0);
121 void demo_reshape(int x, int y)
127 win_aspect = (float)x / (float)y;
129 glViewport(0, 0, x, y);
131 glMatrixMode(GL_PROJECTION);
133 gluPerspective(50.0, win_aspect, 0.5, 500.0);
136 void demo_keyboard(int key, int st)
138 if(st && key == 27) {
143 if(cur_part && cur_part->keyboard) {
144 cur_part->keyboard(key, st);
149 void demo_mbutton(int bn, int st, int x, int y)
151 if(cur_part && cur_part->mbutton) {
152 cur_part->mbutton(bn, st, x, y);
156 void demo_mmotion(int x, int y)
158 if(cur_part && cur_part->mmotion) {
159 cur_part->mmotion(x, y);
163 void demo_sball_motion(int x, int y, int z)
167 void demo_sball_rotate(int x, int y, int z)
171 void demo_sball_button(int bn, int st)