Add Skybox

This commit is contained in:
4VRDriver
2020-09-19 00:21:49 +02:00
parent 717447eebf
commit 242b50e9ef
14 changed files with 220 additions and 13 deletions

View File

@@ -79,4 +79,45 @@ void Entity::updateModelMatrix() {
modelMatrix = translationMatrix * rotationMatrix * scaleMatrix;
}
}
Skybox::Skybox(Model *cubeModel, ShaderProgram *shaderProgram, const char *texturePseudoPath)
: cubeModel(cubeModel),
shaderProgram(shaderProgram),
cubeMap(texturePseudoPath),
vertexArray(cubeModel->getMesh(0)->getVertexArray()) {
// Empty
}
void Skybox::draw(glm::mat4 viewMatrix, glm::mat4 projectionMatrix) {
// To disable face culling first get current state
GLboolean active;
glGetBooleanv(GL_CULL_FACE_MODE, &active);
glDisable(GL_CULL_FACE);
glDepthMask(GL_FALSE);
shaderProgram->bind();
glm::mat4 viewProjectionMatrix = projectionMatrix * glm::mat4(glm::mat3(viewMatrix));
shaderProgram->setUniform("u_viewProjectionMatrix", viewProjectionMatrix);
cubeMap.bind(shaderProgram);
cubeModel->getMesh(0)->drawWithoutTextures(shaderProgram);
cubeMap.unbind();
shaderProgram->unbind();
glDepthMask(GL_TRUE);
// Restore face culling
if(active)
glEnable(GL_CULL_FACE);
else
glDisable(GL_CULL_FACE);
}