void RenderEngine::display() { if(render_engine.is_done()) { render_engine.set_gl_ortho_proj(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); render_engine.draw_texture(); } else { glEnable(GL_DEPTH_TEST); render_engine.set_gl_perspective(); render_engine.set_gl_clearcolor(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); render_engine.set_gl_camera(); render_engine.draw(); glDisable(GL_DEPTH_TEST); } glutSwapBuffers(); }
void RenderEngine::keyboard(unsigned char key, int x, int y) { // The shader to be used when rendering a material is chosen // by setting the "illum" property of the material. This // property is part of the MTL file format ("illum" is short // for "illumination model"). The shader to be used with // each illumination model is specified in the init_tracer // function above. // // Number keys switch the shader used for illumination // models 0 and 1 to the shader at the corresponding index // in the array "shaders" at the top of this file. // // When you switch shaders all previous rendering results // will be erased! if(key >= 48 && key < 48 + static_cast<unsigned char>(render_engine.no_of_shaders())) { unsigned int shader_no = key - 48; if(shader_no != render_engine.get_current_shader()) { render_engine.set_current_shader(shader_no); render_engine.clear_image(); render_engine.redo_display_list(); cout << "Switched to shader number " << shader_no << endl; glutPostRedisplay(); } } switch(key) { // Use '+' and '-' to increase or decrease the number of // jitter samples per pixel in a simple ray tracing case '+': render_engine.increment_pixel_subdivs(); break; case '-': render_engine.decrement_pixel_subdivs(); break; // Press '*' to apply tone mapping case '*': render_engine.apply_tone_map(); break; // Press '/' to unapply tone mapping case '/': render_engine.unapply_tone_map(); break; // Press 'b' to save a bitmap called the same as the last loaded .obj file. case 'b': render_engine.save_as_bitmap(); break; // Press 'r' to start a simple ray tracing (one pass -> done). // To switch back to preview mode after the ray tracing is done // press 'r' again. case 'r': if(render_engine.is_done()) render_engine.undo(); else render_engine.render(); glutPostRedisplay(); break; // Press 's' to toggle shadows on/off case 's': { bool shadows_on = render_engine.toggle_shadows(); render_engine.clear_image(); render_engine.redo_display_list(); cout << "Toggled shadows " << (shadows_on ? "on" : "off") << endl; glutPostRedisplay(); } break; // Press 'x' to switch on material textures. case 'x': render_engine.add_textures(); cout << "Toggled textures on." << endl; break; // Press 'z' to zoom in. case 'z': { render_engine.set_focal_dist(render_engine.get_focal_dist()*1.05f); glutPostRedisplay(); } break; // Press 'Z' to zoom out. case 'Z': { render_engine.set_focal_dist(render_engine.get_focal_dist()/1.05f); glutPostRedisplay(); } break; // Press 'SPACE' to switch between pre-view and your last tracing result. case 32: render_engine.undo(); glutPostRedisplay(); break; // Press 'ESC' to exit the program. case 27: exit(0); } }