From 2afdc35935e6f29584fdf99db4c3b0188bad734b Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 14 Sep 2024 14:55:17 +0200 Subject: [PATCH] Fixes for windows. --- sfw/render_core/3rd_glfw3.h | 38 +++++++++++++++++++++++++++++- sfw/render_gui/imgui_impl_glfw.cpp | 12 ++++------ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/sfw/render_core/3rd_glfw3.h b/sfw/render_core/3rd_glfw3.h index 954c4ed..9be2fdc 100644 --- a/sfw/render_core/3rd_glfw3.h +++ b/sfw/render_core/3rd_glfw3.h @@ -5752,6 +5752,30 @@ GLFWAPI int glfwVulkanSupported(void); */ GLFWAPI const char** glfwGetRequiredInstanceExtensions(uint32_t* count); +/*! @brief Returns the `HWND` of the specified window as a void*, only works on windows + * + * @return The `HWND` of the specified window, or `NULL` if an + * [error](@ref error_handling) occurred. + * + * @errors Possible errors include @ref GLFW_NOT_INITIALIZED. + * + * @remark The `HDC` associated with the window can be queried with the + * [GetDC](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdc) + * function. + * @code + * HDC dc = GetDC(glfwGetWin32WindowAsVPTR(window)); + * @endcode + * This DC is private and does not need to be released. + * + * @thread_safety This function may be called from any thread. Access is not + * synchronized. + * + * @since Added in version 3.0. + * + * @ingroup native + */ +GLFWAPI void *glfwGetWin32WindowAsVPTR(GLFWwindow* window); + #if defined(VK_VERSION_1_0) /*! @brief Returns the address of the specified Vulkan instance function. @@ -10984,7 +11008,7 @@ inline void __glfw_ptr_swap_tmpl(T &x, T &y) { x = y; \ y = t; \ } - + #endif // Per-thread error structure @@ -17045,6 +17069,18 @@ const char* _glfwGetVulkanResultString(VkResult result) ////// GLFW public API ////// ////////////////////////////////////////////////////////////////////////// + +GLFWAPI void *glfwGetWin32WindowAsVPTR(GLFWwindow* handle) +{ +#if defined(_WIN64) || defined(_WIN32) + _GLFWwindow* window = (_GLFWwindow*) handle; + _GLFW_REQUIRE_INIT_OR_RETURN(NULL); + return window->win32.handle; +#else + return NULL; +#endif +} + GLFWAPI int glfwVulkanSupported(void) { _GLFW_REQUIRE_INIT_OR_RETURN(GLFW_FALSE); diff --git a/sfw/render_gui/imgui_impl_glfw.cpp b/sfw/render_gui/imgui_impl_glfw.cpp index 7d32343..a98f2f9 100644 --- a/sfw/render_gui/imgui_impl_glfw.cpp +++ b/sfw/render_gui/imgui_impl_glfw.cpp @@ -90,13 +90,11 @@ // GLFW -#ifdef _WIN32 -#undef APIENTRY -#ifndef GLFW_EXPOSE_NATIVE_WIN32 -#define GLFW_EXPOSE_NATIVE_WIN32 -#endif -//#include // for glfwGetWin32Window() +#if defined(_WIN64) || defined(_WIN32) +#define WIN32_LEAN_AND_MEAN +#include #endif + #ifdef __APPLE__ #ifndef GLFW_EXPOSE_NATIVE_COCOA #define GLFW_EXPOSE_NATIVE_COCOA @@ -627,7 +625,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw ImGuiViewport* main_viewport = ImGui::GetMainViewport(); main_viewport->PlatformHandle = (void*)bd->Window; #ifdef _WIN32 - main_viewport->PlatformHandleRaw = glfwGetWin32Window(bd->Window); + main_viewport->PlatformHandleRaw = glfwGetWin32WindowAsVPTR(bd->Window); #elif defined(__APPLE__) main_viewport->PlatformHandleRaw = (void*)glfwGetCocoaWindow(bd->Window); #else