diff --git a/include/Callbacks.h b/include/Callbacks.h index e07440b..01916f7 100644 --- a/include/Callbacks.h +++ b/include/Callbacks.h @@ -1,10 +1,15 @@ #pragma once #include +#include + +#include "scene.h" namespace Callbacks { - void Register(GLFWwindow* window); + extern Scene* scene_; + + void Register(GLFWwindow* window, Scene* scene); void Keyboard(GLFWwindow* window, int key, int scancode, int action, int mods); void MouseCursor(GLFWwindow* window, double x, double y); diff --git a/source/Callbacks.cpp b/source/Callbacks.cpp index f06ac29..f1c30f9 100644 --- a/source/Callbacks.cpp +++ b/source/Callbacks.cpp @@ -1,10 +1,16 @@ -#include "callbacks.h" -#include "platform_utils.h" -#include "scene.h" #include -void Callbacks::Register(GLFWwindow* window) +#include "callbacks.h" +//#include "platform_utils.h" + +namespace Callbacks { + Scene* scene_ = nullptr; +}; + +void Callbacks::Register(GLFWwindow* window, Scene* scene) { + scene_ = scene; + glfwSetKeyCallback(window, Keyboard); glfwSetCursorPosCallback(window, MouseCursor); glfwSetMouseButtonCallback(window, MouseButton); @@ -22,9 +28,10 @@ void Callbacks::Keyboard(GLFWwindow* window, int key, int scancode, int action, { case 'r': case 'R': - //Scene::ReloadShader(); + if (scene_) { + scene_->ReloadShader(); + } break; - case GLFW_KEY_ESCAPE: glfwSetWindowShouldClose(window, GLFW_TRUE); break; diff --git a/source/main.cpp b/source/main.cpp index 7f3f9e1..ea27254 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -128,6 +128,7 @@ int main() { if (!InitializeGlew()) return -1; Scene scene(kInitWindowWidth, kInitWindowHeight); + Callbacks::Register(window, &scene); scene.Init(); InitializeImGui(window); diff --git a/source/scene.cpp b/source/scene.cpp index 365283c..a612a38 100644 --- a/source/scene.cpp +++ b/source/scene.cpp @@ -128,7 +128,7 @@ void Scene::GenerateGrid(int divisions, std::vector& verts, std::vector< // Currently creates a test triangle and initializes its buffers void Scene::InitBuffers() { - int divisions = 1 + (tessellationFactor / 64); // Number of divisions along one axis of the grid + int divisions = 16; // Number of divisions along one axis of the grid GenerateGrid(divisions, vertices, indices); // Create and bind VAO, VBO, and EBO, and pass the data to OpenGL @@ -189,20 +189,24 @@ void Scene::InitQuadBuffers() { // Allows for runtime shader updates void Scene::ReloadShader() { - GLuint new_shader = InitShader(kVertexShaderPath.c_str(), kTessellationCtrlPath.c_str(), kTessellationEvalPath.c_str(), kFragmentShaderPath.c_str()); - if (new_shader == -1) { + GLuint geo_shader = InitShader(kVertexShaderPath.c_str(), kTessellationCtrlPath.c_str(), kTessellationEvalPath.c_str(), kFragmentShaderPath.c_str()); + GLuint lht_shader = InitShader(kQuadVertexPath.c_str(), kQuadFragmentPath.c_str()); + if (geo_shader == -1 || lht_shader == -1) { DEBUG_BREAK(); glClearColor(1.0f, 0.0f, 1.0f, 0.0f); } else { glClearColor(0.35f, 0.35f, 0.35f, 0.0f); - if (shader_program_ != -1) { + if (shader_program_ != -1 && quad_shader_program_ != -1) { glDeleteProgram(shader_program_); + glDeleteProgram(quad_shader_program_); } - shader_program_ = new_shader; + shader_program_ = geo_shader; + quad_shader_program_ = lht_shader; } } void Scene::Display(GLFWwindow* window) { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); fbo_.Bind(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -210,7 +214,7 @@ void Scene::Display(GLFWwindow* window) { //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); - view_matrix_ = glm::lookAt(glm::vec3(0.0f, 1.4f, -1.4f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); + view_matrix_ = glm::lookAt(glm::vec3(0.0f, 1.4f, 1.4f), glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f)); Uniforms::SceneData.PV = projection_matrix_ * view_matrix_; // Projection-View matrix Uniforms::BufferSceneData();