- unsigned int msec = glutGet(GLUT_ELAPSED_TIME) - start_time;
- float dt = (float)(msec - prev_msec) / 1000.0f;
- prev_msec = msec;
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- view_matrix = Mat4::identity;
- view_matrix.pre_translate(0, 0, -cam_dist);
- view_matrix.pre_rotate(deg_to_rad(cam_phi), 1, 0, 0);
- view_matrix.pre_rotate(deg_to_rad(cam_theta), 0, 1, 0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(view_matrix[0]);
-
- static const Vec3 lpos[] = { Vec3(-50, 75, 100), Vec3(100, 0, 30), Vec3(-10, -10, 60) };
- set_light(0, lpos[0], Vec3(1.0, 0.8, 0.7) * 0.8);
- set_light(1, lpos[1], Vec3(0.6, 0.7, 1.0) * 0.6);
- set_light(2, lpos[2], Vec3(0.8, 1.0, 0.8) * 0.3);
-
- update(dt);
-
- // shadowmap pass
- begin_shadow_pass(lpos[0], Vec3(0, 0, 0), 0.2, 100, 150);
- draw_scene();
- end_shadow_pass();
-
- // regular pass
- const Mat4 &shadow_matrix = get_shadow_matrix();
- Mat4 env_matrix = transpose(view_matrix.upper3x3());
- set_uniform_matrix4(sdr_shadow_notex, "envmap_matrix", env_matrix[0]);
-
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, get_shadow_tex());
- glMatrixMode(GL_TEXTURE);
- glLoadMatrixf(shadow_matrix[0]);
-
- glActiveTexture(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_CUBE_MAP, envmap->get_id());
-
- glActiveTexture(GL_TEXTURE0);
- glMatrixMode(GL_MODELVIEW);
-
- draw_scene();
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
-
-
- if(dbg_show_shadowmap) {
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
-
- glPushAttrib(GL_ENABLE_BIT);
- glUseProgram(0);
- glBindTexture(GL_TEXTURE_2D, get_shadow_tex());
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
- glEnable(GL_TEXTURE_2D);
- glDisable(GL_DEPTH_TEST);
- glDisable(GL_LIGHTING);
- glDisable(GL_BLEND);
-
- glBegin(GL_QUADS);
- glColor4f(1, 1, 1, 1);
- glTexCoord2f(0, 0); glVertex2f(-0.95, -0.95);
- glTexCoord2f(1, 0); glVertex2f(-0.5, -0.95);
- glTexCoord2f(1, 1); glVertex2f(-0.5, -0.5);
- glTexCoord2f(0, 1); glVertex2f(-0.95, -0.5);
- glEnd();
-
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
- glBindTexture(GL_TEXTURE_2D, 0);
-
- glPopAttrib();
-
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- }
-
-
- glutSwapBuffers();
- assert(glGetError() == GL_NO_ERROR);