cimgui is working

This commit is contained in:
Lauchmelder 2022-06-16 18:28:00 +02:00
parent 5fe4b6b935
commit d868ab0ac8
3 changed files with 97 additions and 3 deletions

19
imgui.ini Normal file
View file

@ -0,0 +1,19 @@
[Window][Debug##Default]
Pos=60,60
Size=400,400
Collapsed=0
[Window][Dear ImGui Demo]
ViewportPos=1381,242
ViewportId=0xE927CF2F
Size=550,680
Collapsed=0
[Window][Test Window]
ViewportPos=1469,242
ViewportId=0x872DD4D0
Size=193,115
Collapsed=0
[Docking][Data]

View file

@ -9,12 +9,45 @@ add_executable(sortalgs
"algorithms/shellsort.c"
)
target_include_directories(sortalgs PRIVATE
set(CIMGUI_SOURCE_DIR ${CMAKE_SOURCE_DIR}/vendor/cimgui)
if (WIN32)
add_definitions("-DIMGUI_IMPL_API=extern \"C\" __declspec\(dllexport\)")
else()
add_definitions("-DIMGUI_IMPL_API=extern \"C\" ")
endif()
add_library(cimgui STATIC
${CIMGUI_SOURCE_DIR}/cimgui.cpp
${CIMGUI_SOURCE_DIR}/imgui/imgui.cpp
${CIMGUI_SOURCE_DIR}/imgui/imgui_demo.cpp
${CIMGUI_SOURCE_DIR}/imgui/imgui_draw.cpp
${CIMGUI_SOURCE_DIR}/imgui/imgui_tables.cpp
${CIMGUI_SOURCE_DIR}/imgui/imgui_widgets.cpp
${CIMGUI_SOURCE_DIR}/imgui/backends/imgui_impl_opengl3.cpp
${CIMGUI_SOURCE_DIR}/imgui/backends/imgui_impl_glfw.cpp
)
target_include_directories(cimgui PUBLIC
${CIMGUI_SOURCE_DIR}
${CIMGUI_SOURCE_DIR}/imgui
${CIMGUI_SOURCE_DIR}/imgui/backends
)
target_link_libraries(cimgui PRIVATE
glfw
glad
)
target_include_directories(sortalgs PUBLIC
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_SOURCE_DIR}/vendor/cimgui/generator/output
)
target_link_libraries(sortalgs PRIVATE
glfw
glad
cglm
cimgui
)

View file

@ -6,6 +6,10 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#define CIMGUI_DEFINE_ENUMS_AND_STRUCTS
#include <cimgui.h>
#include <cimgui_impl.h>
#include "visualizers/histogram.h"
#include "algorithms.h"
@ -44,6 +48,18 @@ int init_application(Application* app, int width, int height, const char* title)
glViewport(0, 0, width, height);
igCreateContext(NULL);
ImGuiIO* io = igGetIO(); (void*)io;
io->ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io->ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io->ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init("#version 460");
igStyleColorsDark(NULL);
app->active_visualizer = &histogram_visualizer;
visualizer_data.array_size = 1500;
@ -68,6 +84,10 @@ int init_application(Application* app, int width, int height, const char* title)
void destroy_application(Application* app)
{
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
igDestroyContext(NULL);
app->active_visualizer->exit();
if(app->window)
@ -79,9 +99,9 @@ void run_application(Application* app)
GLFWwindow* window = app->window;
// bubblesort(app);
// mergesort(app);
mergesort(app);
// insertionsort(app);
shellsort(app);
// shellsort(app);
while(!glfwWindowShouldClose(window))
{
@ -96,8 +116,30 @@ int update_screen(Application* app)
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
igNewFrame();
app->active_visualizer->render();
if(igBegin("Test Window", NULL, 0))
{
igText("cImGui is working");
igEnd();
}
igRender();
ImGui_ImplOpenGL3_RenderDrawData(igGetDrawData());
if (igGetIO()->ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
{
GLFWwindow* backup_current_context = glfwGetCurrentContext();
igUpdatePlatformWindows();
igRenderPlatformWindowsDefault(NULL, NULL);
glfwMakeContextCurrent(backup_current_context);
}
glfwSwapBuffers(app->window);
return glfwWindowShouldClose(app->window);
}