Skip to content

Commit

Permalink
Bump Dear ImGui version to 1.89.8
Browse files Browse the repository at this point in the history
Also change the backend from OpenGL2 to OpenGL3
  • Loading branch information
pierre-dejoue committed Aug 4, 2023
1 parent b8b4117 commit 0ae7bf5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmake/third_party/imgui.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ include(FetchContent)
FetchContent_Declare(
imgui
GIT_REPOSITORY https://github.com/ocornut/imgui.git
GIT_TAG v1.89.3
GIT_TAG v1.89.8
)
FetchContent_Populate(imgui)
4 changes: 2 additions & 2 deletions src/gui/imgui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ add_library(imgui
${imgui_SOURCE_DIR}/imgui_widgets.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.h
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl2.h
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl2.cpp
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.h
${imgui_SOURCE_DIR}/backends/imgui_impl_opengl3.cpp
)

target_include_directories(imgui
Expand Down
23 changes: 14 additions & 9 deletions src/gui/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <GLFW/glfw3.h>
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_opengl2.h>
#include <imgui_impl_opengl3.h>

#include <cassert>
#include <iostream>
Expand Down Expand Up @@ -71,8 +71,14 @@ int main(int argc, char *argv[])
glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit())
return 1;
GLFWwindow* window = glfwCreateWindow(1280, 720, picross_title.str().c_str(), NULL, NULL);
if (window == NULL)

// GL 3.0 + GLSL 130
const char* glsl_version = "#version 130";
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

GLFWwindow* window = glfwCreateWindow(1280, 720, picross_title.str().c_str(), nullptr, nullptr);
if (window == nullptr)
return 1;
glfwMakeContextCurrent(window);
glfwSwapInterval(1); // Enable vsync
Expand All @@ -81,11 +87,11 @@ int main(int argc, char *argv[])
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
(void)io; // Unused
UNUSED(io);

// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL2_Init();
ImGui_ImplOpenGL3_Init(glsl_version);

// Style
bool imgui_dark_mode = false;
Expand All @@ -107,7 +113,7 @@ int main(int argc, char *argv[])
glfwPollEvents();

// Start the Dear ImGui frame
ImGui_ImplOpenGL2_NewFrame();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();

Expand Down Expand Up @@ -195,14 +201,13 @@ int main(int argc, char *argv[])
const auto clear_color = static_cast<ImVec4>(imgui_dark_mode ? WindowMainBackgroundColor_Dark : WindowMainBackgroundColor_Classic);
glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
glClear(GL_COLOR_BUFFER_BIT);
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
glfwMakeContextCurrent(window);
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
} // while (!glfwWindowShouldClose(window))

// Cleanup
picross_files.clear();
ImGui_ImplOpenGL2_Shutdown();
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwDestroyWindow(window);
Expand Down

0 comments on commit 0ae7bf5

Please sign in to comment.