create debug window with imgui
parent
e7c4b2d56b
commit
f526e9b152
|
@ -9,4 +9,5 @@ gmon.out*
|
|||
cscope*
|
||||
test.cpp
|
||||
a.out
|
||||
*screenshot*
|
||||
*screenshot*
|
||||
imgui.ini
|
||||
|
|
|
@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.2)
|
|||
|
||||
project(cmake-project-template)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3")
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -O3")
|
||||
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g")
|
||||
|
||||
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef DEBUG_WINDOW_H
|
||||
#define DEBUG_WINDOW_H
|
||||
|
||||
#include <any>
|
||||
#include <string>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace debug{
|
||||
namespace window {
|
||||
void init(GLFWwindow* window);
|
||||
void prerender();
|
||||
void render();
|
||||
void destroy();
|
||||
|
||||
void set_parameter(std::string key, std::any value);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,7 +1,8 @@
|
|||
cmake_minimum_required(VERSION 3.2)
|
||||
project(OpenGLTest)
|
||||
|
||||
set(SOURCE_FILES main.cpp chunk.cpp chunkmanager.cpp chunkmesher.cpp chunkgenerator.cpp renderer.cpp spacefilling.cpp stb_image.cpp utils.cpp OpenSimplexNoise.cpp)
|
||||
set(SOURCE_FILES main.cpp chunk.cpp chunkmanager.cpp chunkmesher.cpp chunkgenerator.cpp
|
||||
debugwindow.cpp renderer.cpp spacefilling.cpp stb_image.cpp utils.cpp OpenSimplexNoise.cpp)
|
||||
|
||||
add_executable(OpenGLTest ${SOURCE_FILES})
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
#include "debugwindow.hpp"
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
#include <imgui/imgui_impl_opengl3.h>
|
||||
#include <imgui/imgui_impl_glfw.h>
|
||||
|
||||
namespace debug{
|
||||
namespace window{
|
||||
|
||||
|
||||
void init(GLFWwindow* window){
|
||||
// Setup Dear ImGui context
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true); // Second param install_callback=true will install GLFW callbacks and chain to existing ones.
|
||||
ImGui_ImplOpenGL3_Init();
|
||||
}
|
||||
|
||||
void prerender(){
|
||||
// Start the Dear ImGui frame
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
ImGui::ShowDemoWindow(); // Show demo window! :)
|
||||
}
|
||||
|
||||
void render(){
|
||||
// (Your code clears your framebuffer, renders your other stuff etc.)
|
||||
ImGui::Render();
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
// (Your code calls glfwSwapBuffers() etc.)
|
||||
}
|
||||
|
||||
void destroy(){
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
}
|
||||
}
|
10
src/main.cpp
10
src/main.cpp
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "chunkmanager.hpp"
|
||||
#include "main.hpp"
|
||||
#include "debugwindow.hpp"
|
||||
#include "renderer.hpp"
|
||||
#include "spacefilling.hpp"
|
||||
#include "shader.hpp"
|
||||
|
@ -22,6 +23,7 @@ int frames = 0;
|
|||
float lastBlockPick=0.0;
|
||||
bool blockpick = false;
|
||||
bool canChangeWireframe = true;
|
||||
bool cursor = false;
|
||||
|
||||
int main()
|
||||
{
|
||||
|
@ -67,8 +69,10 @@ int main()
|
|||
sines[i] = sin(3.14 / 180 * i);
|
||||
cosines[i] = cos(3.14 / 180 * i);
|
||||
}
|
||||
|
||||
SpaceFilling::initLUT();
|
||||
chunkmanager::init();
|
||||
debug::window::init(window);
|
||||
renderer::init(window);
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
|
@ -112,6 +116,7 @@ int main()
|
|||
// Cleanup allocated memory
|
||||
chunkmanager::destroy();
|
||||
renderer::destroy();
|
||||
debug::window::destroy();
|
||||
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
|
@ -157,5 +162,10 @@ void processInput(GLFWwindow *window)
|
|||
|
||||
if(glfwGetKey(window, GLFW_KEY_F2) == GLFW_PRESS) renderer::saveScreenshot();
|
||||
if(glfwGetKey(window, GLFW_KEY_F3) == GLFW_PRESS) renderer::saveScreenshot(true);
|
||||
if(glfwGetKey(window, GLFW_KEY_M) == GLFW_PRESS) {
|
||||
cursor = !cursor;
|
||||
glfwSetInputMode(window, GLFW_CURSOR, cursor ? GLFW_CURSOR_NORMAL : GLFW_CURSOR_DISABLED);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "chunkmanager.hpp"
|
||||
#include "chunkmesher.hpp"
|
||||
#include "debugwindow.hpp"
|
||||
#include "globals.hpp"
|
||||
#include "stb_image.h"
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
|
@ -118,6 +119,10 @@ namespace renderer{
|
|||
glClearColor(0.431f, 0.694f, 1.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
/* UPDATE IMGUI */
|
||||
debug::window::prerender();
|
||||
|
||||
/* RENDER THE WORLD TO TEXTURE */
|
||||
int total{0}, toGpu{0};
|
||||
glm::vec4 frustumPlanes[6];
|
||||
theCamera.getFrustumPlanes(frustumPlanes, true);
|
||||
|
@ -205,7 +210,7 @@ namespace renderer{
|
|||
}
|
||||
render_todelete.clear();
|
||||
|
||||
|
||||
/* DISPLAY TEXTURE ON A QUAD THAT FILLS THE SCREEN */
|
||||
// Now to render the quad, with the texture on top
|
||||
// Switch to the default frame buffer
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
@ -222,6 +227,8 @@ namespace renderer{
|
|||
quadShader->setInt("crosshairType", 1);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindVertexArray(0);
|
||||
|
||||
debug::window::render();
|
||||
}
|
||||
|
||||
void framebuffer_size_callback(GLFWwindow *window, int width, int height){
|
||||
|
@ -271,6 +278,7 @@ namespace renderer{
|
|||
|
||||
void destroy(){
|
||||
delete theShader;
|
||||
delete quadShader;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue