Add ImGui and refactor
This commit is contained in:
parent
b416f8da27
commit
4261ce59f7
28
src/main.cpp
28
src/main.cpp
|
@ -2,16 +2,19 @@
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include <imgui_impl_glfw.h>
|
||||||
|
#include <imgui_impl_opengl3.h>
|
||||||
|
|
||||||
#include "scene.h"
|
#include "scene.h"
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
if (!glfwInit()){
|
if (!glfwInit()) {
|
||||||
std::cerr << "Failed to initialize GLFW" << std::endl;
|
std::cerr << "Failed to initialize GLFW" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWwindow* window = glfwCreateWindow(800, 600, "TerraVisor", nullptr, nullptr);
|
GLFWwindow* window = glfwCreateWindow(800, 600, "TerraVisor", nullptr, nullptr);
|
||||||
if(!window){
|
if(!window) {
|
||||||
std::cerr << "Failed to create GLFW window" << std::endl;
|
std::cerr << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -19,18 +22,31 @@ int main(){
|
||||||
|
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
if(glewInit() != GLEW_OK){
|
if(glewInit() != GLEW_OK) {
|
||||||
std::cerr << "Failed to initialize GLEW" << std::endl;
|
std::cerr << "Failed to initialize GLEW" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Scene::Init();
|
||||||
|
|
||||||
|
//Init ImGui
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||||
|
ImGui_ImplOpenGL3_Init("#version 150");
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)){
|
while (!glfwWindowShouldClose(window)) {
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
Scene::Idle();
|
Scene::Idle();
|
||||||
glfwSwapBuffers(window);
|
Scene::Display(window);
|
||||||
|
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup ImGui
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -8,14 +8,20 @@
|
||||||
|
|
||||||
#include "Scene.h"
|
#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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue