Skip to content

Commit

Permalink
imgui: switch to opengl 2 for real
Browse files Browse the repository at this point in the history
  • Loading branch information
im-tem committed Nov 3, 2024
1 parent bb62bd8 commit a9fd334
Show file tree
Hide file tree
Showing 3 changed files with 12,929 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ target_compile_definitions(freetype PRIVATE FT2_BUILD_LIBRARY PRIVATE DLL_EXPORT
FILE(GLOB IMGUI_SRC ${CMAKE_SOURCE_DIR}/libs/imgui/*.cpp)
FILE(GLOB IMGUI_BACKENDS_DIR ${CMAKE_SOURCE_DIR}/libs/imgui/backends/)
set(IMGUI_BACKENDS_DIR ${CMAKE_SOURCE_DIR}/libs/imgui/backends/)
add_library(imgui ${IMGUI_SRC} ${CMAKE_SOURCE_DIR}/libs/imgui/misc/freetype/imgui_freetype.h ${CMAKE_SOURCE_DIR}/libs/imgui/misc/freetype/imgui_freetype.cpp ${IMGUI_BACKENDS_DIR}/imgui_impl_opengl3.cpp ${IMGUI_BACKENDS_DIR}/imgui_impl_opengl3.h ${IMGUI_BACKENDS_DIR}/imgui_impl_opengl3_loader.h ${IMGUI_BACKENDS_DIR}/imgui_impl_win32.h ${IMGUI_BACKENDS_DIR}/imgui_impl_win32.cpp)
add_library(imgui ${IMGUI_SRC} ${CMAKE_SOURCE_DIR}/libs/imgui/misc/freetype/imgui_freetype.h ${CMAKE_SOURCE_DIR}/libs/imgui/misc/freetype/imgui_freetype.cpp ${IMGUI_BACKENDS_DIR}/imgui_impl_opengl2.cpp ${IMGUI_BACKENDS_DIR}/imgui_impl_opengl2.h ${IMGUI_BACKENDS_DIR}/imgui_impl_opengl3.cpp ${IMGUI_BACKENDS_DIR}/imgui_impl_opengl3.h ${IMGUI_BACKENDS_DIR}/imgui_impl_opengl3_loader.h ${IMGUI_BACKENDS_DIR}/imgui_impl_win32.h ${IMGUI_BACKENDS_DIR}/imgui_impl_win32.cpp)
target_include_directories(imgui PUBLIC "${CMAKE_SOURCE_DIR}/libs/freetype/include")
target_compile_options(imgui PUBLIC "/MD")
target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE)
Expand Down
21 changes: 14 additions & 7 deletions repentogon/ImGuiFeatures/ImGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
#include "Lang.h"

#include <Windows.h>
#include <gl/GL.h>
#include <gl/gl.h>
#include "glext.h"
#include <sstream>
#include <algorithm>

#include "imgui.h"
#include "imgui_freetype.h"
#include "imgui_impl_opengl3.h"
#include "imgui_impl_opengl2.h"
#include "imgui_impl_win32.h"
#include "../MiscFunctions.h"
#include "../REPENTOGONOptions.h"
Expand Down Expand Up @@ -476,6 +477,8 @@ void RenderLuamodErrorPopup() {

ImFont* imFontUnifont = NULL;

PFNGLUSEPROGRAMPROC glUseProgram;

void __stdcall RunImGui(HDC hdc) {
static std::map<int, ImFont*> fonts;

Expand All @@ -487,10 +490,10 @@ void __stdcall RunImGui(HDC hdc) {
HWND window = WindowFromDC(hdc);
windowProc = (WNDPROC)SetWindowLongPtr(window,
GWLP_WNDPROC, (LONG_PTR)windowProc_hook);

glUseProgram = (PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram");
ImGui::CreateContext();
ImGui_ImplWin32_Init(window);
ImGui_ImplOpenGL3_Init();
ImGui_ImplOpenGL2_Init();
ImGui::StyleColorsDark();
ImGui::GetStyle().AntiAliasedFill = false;
ImGui::GetStyle().AntiAliasedLines = false;
Expand Down Expand Up @@ -559,8 +562,7 @@ void __stdcall RunImGui(HDC hdc) {
logViewer.AddLog("[REPENTOGON]", "Initialized Dear ImGui v%s\n", IMGUI_VERSION);
printf("[REPENTOGON] Dear ImGui v%s initialized! Any further logs can be seen in the in-game log viewer.\n", IMGUI_VERSION);
}

ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplOpenGL2_NewFrame();
ImGui_ImplWin32_NewFrame();
ImGui::NewFrame();
UpdateImGuiSettings();
Expand Down Expand Up @@ -629,8 +631,13 @@ void __stdcall RunImGui(HDC hdc) {

ImGui::Render();


GLint last_program;
glGetIntegerv(GL_CURRENT_PROGRAM, &last_program);
glUseProgram(0);
// Draw the overlay
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
ImGui_ImplOpenGL2_RenderDrawData(ImGui::GetDrawData());
glUseProgram(last_program);
}


Expand Down
Loading

0 comments on commit a9fd334

Please sign in to comment.