diff --git a/core/Engine.cpp b/core/Engine.cpp index 948e8eb..aaf75aa 100644 --- a/core/Engine.cpp +++ b/core/Engine.cpp @@ -68,6 +68,13 @@ Engine::Engine(int windowWidth, int windowHeight, const char *name = "Feather Pr engine->mouseX = xpos; engine->mouseY = ypos; }); + + setClearColor(0.1f, 0.1f, 0.1f, 1.0f); + + glDepthFunc(GL_LESS); // Specify the depth test for the z-buffer + glEnable(GL_DEPTH_TEST); // Enable the z-buffer test in the rasterization + glEnable(GL_BLEND); + glCullFace(GL_BACK); // Specifies the faces to cull (here the ones pointing away from the camera) } Engine::~Engine() = default; diff --git a/core/Engine.h b/core/Engine.h index 58f96cc..05a73df 100644 --- a/core/Engine.h +++ b/core/Engine.h @@ -42,6 +42,10 @@ class Engine { return (float) glfwGetTime(); } + void setClearColor(float r, float g, float b, float a) { + glClearColor(r, g, b, a); + } + void start() { while (!glfwWindowShouldClose(window)) { onExecuteLoopObservable.notifyObservers(); diff --git a/core/materials/Material.cpp b/core/materials/Material.cpp index d58320d..2fa5585 100644 --- a/core/materials/Material.cpp +++ b/core/materials/Material.cpp @@ -61,6 +61,12 @@ void Material::compile() { void Material::bind() { glUseProgram(_program); + + if (_isBackFaceCullingEnabled) { + glEnable(GL_CULL_FACE); // Enables face culling (based on the orientation defined by the CW/CCW enumeration). + } else { + glDisable(GL_CULL_FACE); + } } void Material::setMat4(const char *uniformName, const glm::mat4 *matrix) const { diff --git a/core/materials/Material.h b/core/materials/Material.h index fa0f3be..d27a017 100644 --- a/core/materials/Material.h +++ b/core/materials/Material.h @@ -13,23 +13,34 @@ class Material { public: - explicit Material(const char* shaderFolder); + explicit Material(const char *shaderFolder); + void compile(); + virtual void bind(); + virtual void unbind(); - void setMat4(const char* uniformName, const glm::mat4 * matrix) const; - void setVec3(const char* uniformName, const glm::vec3 * vector) const; - void setInt(const char* uniformName, int integer) const; + void setMat4(const char *uniformName, const glm::mat4 *matrix) const; + + void setVec3(const char *uniformName, const glm::vec3 *vector) const; - void bindTexture(const char* uniformName, Texture *texture, int id) const; + void setInt(const char *uniformName, int integer) const; - void setDefine(const char* defineName); + void bindTexture(const char *uniformName, Texture *texture, int id) const; + + void setDefine(const char *defineName); + + bool isBackFaceCullingEnabled() const { + return _isBackFaceCullingEnabled; + } private: GLuint _program; std::string _vertexShaderCode; std::string _fragmentShaderCode; + + bool _isBackFaceCullingEnabled = true; }; diff --git a/main.cpp b/main.cpp index 0f2e22e..8440ada 100644 --- a/main.cpp +++ b/main.cpp @@ -52,14 +52,7 @@ int main() { CelestialBody moon("moon", 0.25, 5, 5, 2, &moonMat, scene); CelestialBody mars("mars", 0.35, 10, 12, 13, &marsMat, scene); - - glCullFace(GL_BACK); // Specifies the faces to cull (here the ones pointing away from the camera) - glEnable(GL_CULL_FACE); // Enables face culling (based on the orientation defined by the CW/CCW enumeration). - glDepthFunc(GL_LESS); // Specify the depth test for the z-buffer - glEnable(GL_DEPTH_TEST); // Enable the z-buffer test in the rasterization - glEnable(GL_BLEND); - glClearColor(0.1f, 0.1f, 0.1f, 1.0f); - + CelestialBody *currentTarget = &sun; engine.onKeyPressObservable.add([¤tTarget, &sun, &earth, &moon, &engine](int key) {