GLUSboolean display(GLUSfloat time) { glClearColor(0.75f, 0.75f, 1.0f, 1.0f); glClearDepth(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); g_camTimer.Update(time); float cyclicAngle = g_camTimer.GetAlpha() * 6.28f; float hOffset = cosf(cyclicAngle) * 0.25f; float vOffset = sinf(cyclicAngle) * 0.25f; GLfloat modelViewMatrix[16]; glusMatrix4x4LookAtf(modelViewMatrix , hOffset, 1.0f, -64.0f, hOffset, -5.0f + vOffset, -44.0f, 0.0f, 1.0f, 0.0f); glUseProgram(g_program.program); glUniformMatrix4fv(g_program.modelViewUnif, 1, GL_FALSE, modelViewMatrix); glActiveTexture(GL_TEXTURE0 + g_colorTexUnit); glBindTexture(GL_TEXTURE_2D, g_useMipmapTexture ? g_mipmapTestTexture : g_checkerTexture); glBindSampler(g_colorTexUnit, g_samplers[g_currSampler]); Mesh *mesh = g_drawCorridor ? g_pCorridor : g_pPlane; mesh->render("tex"); glBindSampler(g_colorTexUnit, 0); glBindTexture(GL_TEXTURE_2D, 0); glUseProgram(0); return GLUS_TRUE; }
glm::vec4 CalcLightPosition() { float fCurrTimeThroughLoop = g_LightTimer.GetAlpha(); glm::vec4 ret(0.0f, g_fLightHeight, 0.0f, 1.0f); ret.x = cosf(fCurrTimeThroughLoop * (3.14159f * 2.0f)) * g_fLightRadius; ret.z = sinf(fCurrTimeThroughLoop * (3.14159f * 2.0f)) * g_fLightRadius; return ret; }
//Called to update the display. //You should call glutSwapBuffers after all of your rendering to display what you rendered. //If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function. void display() { glClearColor(0.75f, 0.75f, 1.0f, 1.0f); glClearDepth(1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(g_pPlane && g_pCorridor) { g_camTimer.Update(); float cyclicAngle = g_camTimer.GetAlpha() * 6.28f; float hOffset = cosf(cyclicAngle) * 0.25f; float vOffset = sinf(cyclicAngle) * 0.25f; glutil::MatrixStack modelMatrix; const glm::mat4 &worldToCamMat = glm::lookAt( glm::vec3(hOffset, 1.0f, -64.0f), glm::vec3(hOffset, -5.0f + vOffset, -44.0f), glm::vec3(0.0f, 1.0f, 0.0f)); modelMatrix *= worldToCamMat; const ProgramData &prog = g_drawGammaProgram ? g_progGamma : g_progNoGamma; glUseProgram(prog.theProgram); glUniformMatrix4fv(prog.modelToCameraMatrixUnif, 1, GL_FALSE, glm::value_ptr(modelMatrix.Top())); glActiveTexture(GL_TEXTURE0 + g_colorTexUnit); glBindTexture(GL_TEXTURE_2D, g_drawGammaTexture ? g_gammaTexture : g_linearTexture); glBindSampler(g_colorTexUnit, g_samplers[g_currSampler]); if(g_drawCorridor) g_pCorridor->Render("tex"); else g_pPlane->Render("tex"); glBindSampler(g_colorTexUnit, 0); glBindTexture(GL_TEXTURE_2D, 0); glUseProgram(0); } glutPostRedisplay(); glutSwapBuffers(); }