//Called after the window and OpenGL are initialized. Called exactly once, before the main loop. void init() { InitializePrograms(); try { g_pScene = new Scene(); } catch(std::exception &except) { printf("%s\n", except.what()); throw; } SetupDaytimeLighting(); g_lights.CreateTimer("tetra", Framework::Timer::TT_LOOP, 2.5f); glutMouseFunc(MouseButton); glutMotionFunc(MouseMotion); glutMouseWheelFunc(MouseWheel); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); const float depthZNear = 0.0f; const float depthZFar = 1.0f; glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glDepthFunc(GL_LEQUAL); glDepthRange(depthZNear, depthZFar); glEnable(GL_DEPTH_CLAMP); //Setup our Uniform Buffers glGenBuffers(1, &g_lightUniformBuffer); glBindBuffer(GL_UNIFORM_BUFFER, g_lightUniformBuffer); glBufferData(GL_UNIFORM_BUFFER, sizeof(LightBlock), NULL, GL_DYNAMIC_DRAW); glGenBuffers(1, &g_projectionUniformBuffer); glBindBuffer(GL_UNIFORM_BUFFER, g_projectionUniformBuffer); glBufferData(GL_UNIFORM_BUFFER, sizeof(ProjectionBlock), NULL, GL_DYNAMIC_DRAW); //Bind the static buffers. glBindBufferRange(GL_UNIFORM_BUFFER, g_lightBlockIndex, g_lightUniformBuffer, 0, sizeof(LightBlock)); glBindBufferRange(GL_UNIFORM_BUFFER, g_projectionBlockIndex, g_projectionUniformBuffer, 0, sizeof(ProjectionBlock)); glBindBuffer(GL_UNIFORM_BUFFER, 0); }
//Called whenever a key on the keyboard was pressed. //The key is given by the ''key'' parameter, which is in ASCII. //It's often a good idea to have the escape key (ASCII value 27) call glutLeaveMainLoop() to //exit the program. void keyboard(unsigned char key, int x, int y) { bool bChangedShininess = false; bool bChangedLightModel = false; switch (key) { case 27: delete g_pScene; g_pScene = NULL; glutLeaveMainLoop(); return; case 'p': g_lights.TogglePause(g_eTimerMode); break; case '-': g_lights.RewindTime(g_eTimerMode, 1.0f); break; case '=': g_lights.FastForwardTime(g_eTimerMode, 1.0f); break; case 't': g_bDrawCameraPos = !g_bDrawCameraPos; break; case '1': g_eTimerMode = TIMER_ALL; printf("All\n"); break; case '2': g_eTimerMode = TIMER_SUN; printf("Sun\n"); break; case '3': g_eTimerMode = TIMER_LIGHTS; printf("Lights\n"); break; case 'l': SetupDaytimeLighting(); break; case 'L': SetupNighttimeLighting(); break; case 'k': SetupHDRLighting(); break; case 32: { float sunAlpha = g_lights.GetSunTime(); float sunTimeHours = sunAlpha * 24.0f + 12.0f; sunTimeHours = sunTimeHours > 24.0f ? sunTimeHours - 24.0f : sunTimeHours; int sunHours = int(sunTimeHours); float sunTimeMinutes = (sunTimeHours - sunHours) * 60.0f; int sunMinutes = int(sunTimeMinutes); printf("%02i:%02i\n", sunHours, sunMinutes); } break; } g_viewPole.CharPress(key); }