Add ImGui and refactor

This commit is contained in:
Jack Christensen 2024-08-11 14:52:38 -04:00
parent b416f8da27
commit 4261ce59f7
2 changed files with 32 additions and 10 deletions

View File

@ -2,16 +2,19 @@
#include <GLFW/glfw3.h>
#include <iostream>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl3.h>
#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;

View File

@ -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);
}