From 4261ce59f7749e9d2a40741b5e058280aae9aaa8 Mon Sep 17 00:00:00 2001 From: Jack Christensen Date: Sun, 11 Aug 2024 14:52:38 -0400 Subject: [PATCH] Add ImGui and refactor --- src/main.cpp | 28 ++++++++++++++++++++++------ src/scene.cpp | 14 ++++++++++---- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f3f3d75..f2081d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,16 +2,19 @@ #include #include +#include +#include + #include "scene.h" int main(){ - if (!glfwInit()){ + if (!glfwInit()) { std::cerr << "Failed to initialize GLFW" << std::endl; return -1; } GLFWwindow* window = glfwCreateWindow(800, 600, "TerraVisor", nullptr, nullptr); - if(!window){ + if(!window) { std::cerr << "Failed to create GLFW window" << std::endl; glfwTerminate(); return -1; @@ -19,18 +22,31 @@ int main(){ glfwMakeContextCurrent(window); glewExperimental = GL_TRUE; - if(glewInit() != GLEW_OK){ + if(glewInit() != GLEW_OK) { std::cerr << "Failed to initialize GLEW" << std::endl; return -1; } + + Scene::Init(); + + //Init ImGui + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGui_ImplGlfw_InitForOpenGL(window, true); + ImGui_ImplOpenGL3_Init("#version 150"); - while (!glfwWindowShouldClose(window)){ - glClear(GL_COLOR_BUFFER_BIT); + while (!glfwWindowShouldClose(window)) { Scene::Idle(); - glfwSwapBuffers(window); + Scene::Display(window); + glfwPollEvents(); } + // Cleanup ImGui + ImGui_ImplOpenGL3_Shutdown(); + ImGui_ImplGlfw_Shutdown(); + ImGui::DestroyContext(); + glfwDestroyWindow(window); glfwTerminate(); return 0; diff --git a/src/scene.cpp b/src/scene.cpp index 593c89b..77712e4 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -8,14 +8,20 @@ #include "Scene.h" -void Scene::DrawGUI(GLFWwindow* window){ +void Scene::DrawGUI(GLFWwindow* window) { } -void Scene::Display(GLFWwindow* window){ +void Scene::Display(GLFWwindow* window) { + glClear(GL_COLOR_BUFFER_BIT); + glfwSwapBuffers(window); } -void Scene::Idle(){ +void Scene::Idle() { } -void Scene::Init(){ +void Scene::Init() { + glewInit(); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); }