void drawSkybox(Context &ctx) { glm::mat4 view; getViewMatrix(&view); glm::mat4 view_transpose = glm::transpose(view); float fovy = getFovy(ctx); float aspect = ctx.aspect; // Activate program glUseProgram(ctx.skyboxProgram); // Bind textures glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_CUBE_MAP, ctx.cubemap); glUniform1i(glGetUniformLocation(ctx.skyboxProgram, "u_cubemap"), /*GL_TEXTURE0*/ 0); glUniformMatrix4fv(glGetUniformLocation(ctx.skyboxProgram, "u_view_transpose"), 1, GL_FALSE, &view_transpose[0][0]); glUniform1f(glGetUniformLocation(ctx.skyboxProgram, "u_fovy"), fovy); glUniform1f(glGetUniformLocation(ctx.skyboxProgram, "u_aspect"), aspect); // Draw! glBindVertexArray(ctx.skyboxVAO.vao); glDrawElements(GL_TRIANGLES, ctx.skyboxVAO.numIndices, GL_UNSIGNED_BYTE, 0); glBindVertexArray(ctx.defaultVAO); }
/************************************** Debug Function. ***************************************/ void Camera::debug(){ system("clear"); cout << " Eye: " << getEyeX() << " " << getEyeY() << " " << getEyeZ() << endl; cout << " Center: " << getCenterX() << " " << getCenterY() << " " << getCenterZ() << endl; cout << " Up: " << getUpX() << " " << getUpY() << " " << getUpZ() << endl; cout << endl; cout << " Perspective: " << getFovy() << " " << getAspect() << " " << getZNear() << " " << getZFar() << endl; }
std::string PclCameraWrapper::toString() { std::stringstream ss; ss << "[Camera] Position: " << getPos(); ss << ", Up vector: " << getView(); ss << ", Focal point: " << getFocal(); ss << ", Clipping planes depth: " << getClip(); ss << ", Fovy: " << getFovy(); // Additional infos ss << "\n[Camera] Zoom factor" << zoomFactor(); return ss.str(); }
// MODIFY THIS FUNCTION void drawMesh(Context &ctx, GLuint program, const MeshVAO &meshVAO) { // Define uniforms glm::mat4 model = trackballGetRotationMatrix(ctx.trackball); glm::mat4 view; getViewMatrix(&view); float zNear = 0.1f; float zFar = 100.f; glm::mat4 projection; if (ctx.lensType == LensType::PERSPECTIVE) { float fovy = getFovy(ctx); projection = glm::perspective(fovy, ctx.aspect, zNear, zFar); } else { float hh = 2.0f / pow(2.0f, ctx.zoom); projection = glm::ortho(-hh * ctx.aspect, hh * ctx.aspect, -hh, hh, zNear, zFar); } glm::mat4 mv = view * model; glm::mat4 mvp = projection * mv; // Activate program glUseProgram(program); // Bind textures // ... glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_CUBE_MAP, ctx.cubemap_prefiltered_levels[ctx.cubemap_index]); //glBindTexture(GL_TEXTURE_CUBE_MAP, ctx.cubemap_prefiltered_mipmap); glUniform1i(glGetUniformLocation(program, "u_cubemap"), /*GL_TEXTURE0*/ 0); //glUniform1f(glGetUniformLocation(program, "u_cubemap_lod"), (float)ctx.cubemap_index); //glBindTexture(GL_TEXTURE_CUBE_MAP, 0); // Pass uniforms glUniformMatrix4fv(glGetUniformLocation(program, "u_v"), 1, GL_FALSE, &view[0][0]); glUniformMatrix4fv(glGetUniformLocation(program, "u_mv"), 1, GL_FALSE, &mv[0][0]); glUniformMatrix4fv(glGetUniformLocation(program, "u_mvp"), 1, GL_FALSE, &mvp[0][0]); glUniform1f(glGetUniformLocation(program, "u_time"), ctx.elapsed_time); // ... glUniform3fv(glGetUniformLocation(program, "u_ambient_light"), 1, &ctx.ambient_light[0]); glUniform3fv(glGetUniformLocation(program, "u_light_position"), 1, &ctx.light_position[0]); glUniform3fv(glGetUniformLocation(program, "u_light_color"), 1, &ctx.light_color[0]); glUniform3fv(glGetUniformLocation(program, "u_diffuse_color"), 1, &ctx.diffuse_color[0]); glUniform3fv(glGetUniformLocation(program, "u_specular_color"), 1, &ctx.specular_color[0]); glUniform1f(glGetUniformLocation(program, "u_specular_power"), ctx.specular_power); glUniform1f(glGetUniformLocation(program, "u_ambient_weight"), ctx.ambient_weight); glUniform1f(glGetUniformLocation(program, "u_diffuse_weight"), ctx.diffuse_weight); glUniform1f(glGetUniformLocation(program, "u_specular_weight"), ctx.specular_weight); glUniform1i(glGetUniformLocation(program, "u_color_mode"), ctx.color_mode); glUniform1i(glGetUniformLocation(program, "u_use_gamma_correction"), ctx.use_gamma_correction); glUniform1i(glGetUniformLocation(program, "u_use_color_inversion"), ctx.use_color_inversion); // Draw! glBindVertexArray(meshVAO.vao); glDrawElements(GL_TRIANGLES, meshVAO.numIndices, GL_UNSIGNED_INT, 0); glBindVertexArray(ctx.defaultVAO); }
/*************************************** **************************************** Others and the most importants functions **************************************** ****************************************/ void Camera::setPerspective(){ glEnable(GL_DEPTH_TEST); glMatrixMode(GL_PROJECTION); gluPerspective(getFovy(),getAspect(),getZNear(),getZFar()); glutSetCursor(GLUT_CURSOR_NONE); }