added imgui

This commit is contained in:
Lauchmelder 2021-12-21 15:22:47 +01:00
parent c6189b2dc3
commit f02b7f76cf
8 changed files with 58 additions and 7 deletions

3
.gitmodules vendored
View file

@ -4,3 +4,6 @@
[submodule "vendor/glm"]
path = vendor/glm
url = git@github.com:g-truc/glm.git
[submodule "vendor/imgui"]
path = vendor/imgui
url = git@github.com:ocornut/imgui.git

View file

@ -5,6 +5,8 @@ cmake_minimum_required (VERSION 3.8)
project ("Visualizer")
set(VENDOR_DIR ${CMAKE_SOURCE_DIR}/vendor)
find_package(GLFW3)
if(NOT GLFW3_FOUND)
message(STATUS "Could not find GLFW binaries on system, building from source instead")

View file

@ -5,6 +5,9 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "imgui.h"
#include "backends/imgui_impl_glfw.h"
#include "backends/imgui_impl_opengl3.h"
#ifdef NDEBUG
#define FULLSCREEN
@ -12,6 +15,10 @@
Application::~Application()
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
if (cube != nullptr)
delete cube;
@ -95,7 +102,20 @@ void Application::Init(int width, int height, const std::string& title)
}
);
// Set up ImGui
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 460 core");
ImGui::StyleColorsDark();
cube = new Cuboid();
cubePosition = glm::vec3(0.0f);
cubeOrientation = glm::vec3(0.0f);
cubeScale = glm::vec3(1.0f);
}
void Application::Launch()
@ -104,13 +124,28 @@ void Application::Launch()
{
glfwPollEvents();
cube->Rotate(glm::vec3(0.2f, 1.0f, -0.4f), 1.0f);
cube->SetPosition(cubePosition);
cube->SetRotation(cubeOrientation);
cube->SetScale(cubeScale);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
cube->Render();
ImGui::Begin("Debug");
ImGui::SliderFloat3("Position", &(cubePosition[0]), -2.0f, 2.0f);
ImGui::SliderFloat3("Orientation", &(cubeOrientation[0]), 0.0f, glm::two_pi<float>());
ImGui::SliderFloat3("Scale", &(cubeScale[0]), 0.0f, 2.0f);
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
}
}

View file

@ -34,5 +34,6 @@ public:
private:
GLFWwindow* window = nullptr;
glm::vec3 cubeOrientation, cubePosition, cubeScale;
Cuboid* cube;
};

View file

@ -3,13 +3,22 @@ add_executable(visualizer
"backend/VertexArrayObject.cpp" "backend/Shader.cpp" "Cuboid.cpp" "backend/Drawable.cpp" "backend/Transformable.cpp")
target_sources(visualizer PUBLIC
${CMAKE_SOURCE_DIR}/vendor/glad/src/glad.c
${VENDOR_DIR}/glad/src/glad.c
${VENDOR_DIR}/imgui/backends/imgui_impl_opengl3.cpp
${VENDOR_DIR}/imgui/backends/imgui_impl_glfw.cpp
${VENDOR_DIR}/imgui/imgui.cpp
${VENDOR_DIR}/imgui/imgui_draw.cpp
${VENDOR_DIR}/imgui/imgui_tables.cpp
${VENDOR_DIR}/imgui/imgui_widgets.cpp
${VENDOR_DIR}/imgui/imgui_demo.cpp
)
target_include_directories(visualizer PRIVATE
${GLFW3_INCLUDE_DIRS}
${GLM_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/vendor/glad/include
${VENDOR_DIR}/glad/include
${VENDOR_DIR}/imgui
)
target_link_libraries(visualizer PRIVATE

View file

@ -46,7 +46,7 @@ void Transformable::Rotate(const glm::vec3& axis, float angle)
CalculateTransformationMatrix();
}
const glm::vec3& Transformable::SetScale()
const glm::vec3& Transformable::GetScale()
{
return scale;
}
@ -66,7 +66,7 @@ void Transformable::Scale(const glm::vec3& factor)
void Transformable::CalculateTransformationMatrix()
{
transformation = glm::mat4(1.0f);
glm::scale(transformation, scale);
transformation = glm::translate(transformation, position);
transformation *= glm::toMat4(orientation);
glm::translate(transformation, position);
transformation = glm::scale(transformation, scale);
}

View file

@ -17,7 +17,7 @@ public:
void SetRotation(const glm::vec3& eulerAngles);
void Rotate(const glm::vec3& axis, float angle);
const glm::vec3& SetScale();
const glm::vec3& GetScale();
void SetScale(const glm::vec3& scale);
void Scale(const glm::vec3& factor);

1
vendor/imgui vendored Submodule

@ -0,0 +1 @@
Subproject commit 4bad852a785d6361ab0744c28f3ca3dbb847a8fc