Skip to content

Commit b0dda46

Browse files
committed
Win32 Support + MingW CrossCompile
Win32 with dx9 support derived from the imgui example code. This adds a lot to the renderer interface. Compilation was so far only tested with mingw version of gcc
1 parent 90cb96a commit b0dda46

15 files changed

+1047
-175
lines changed

CMakeLists.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ if(EMSCRIPTEN)
1919
set(GL_LIBRARIES GL)
2020

2121
set(EMSCRIPTEN_ENABLED ON)
22+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
23+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
2224
else()
2325
find_package(PkgConfig)
2426

@@ -60,6 +62,16 @@ if(EMSCRIPTEN)
6062
target_link_libraries(imgui-int PUBLIC GL) # TODO GL finder does not support emscripten yet..
6163
target_include_directories(imgui-int PRIVATE
6264
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/emscripten>)
65+
elseif(${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
66+
target_sources(imgui-int
67+
PRIVATE
68+
src/win32/select_win32_renderer.cpp
69+
src/win32/select_win32_renderer.h
70+
src/win32/system_integration.cpp
71+
src/win32/system_integration.h
72+
src/dx9/renderer.cpp
73+
src/dx9/renderer.h)
74+
target_link_libraries(imgui-int PRIVATE d3d9 dinput wsock32)
6375
elseif(GL_FOUND AND GLEW_FOUND)
6476
target_sources(imgui-int
6577
PRIVATE
@@ -69,7 +81,7 @@ elseif(GL_FOUND AND GLEW_FOUND)
6981
target_compile_options(imgui-int PRIVATE -DGL)
7082
endif()
7183

72-
if(SDL_FOUND)
84+
if(SDL_FOUND AND NOT WIN32)
7385
target_sources(imgui-int
7486
PRIVATE
7587
src/sdl/select_sdl_renderer.h
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
SET(CMAKE_SYSTEM_NAME Windows)
2+
3+
set(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32/
4+
/usr/share/mingw-w64/)
5+
6+
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
7+
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
8+
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
9+
10+
set(COMPILER_PREFIX x86_64-w64-mingw32)
11+
12+
set(CMAKE_CXX_COMPILER ${COMPILER_PREFIX}-c++-posix)
13+
set(CMAKE_C_COMPILER ${COMPILER_PREFIX}-gcc-posix)
14+
set(CMAKE_RC_COMPILER ${COMPILER_PREFIX}-windres)

include/imgui/renderer.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,25 @@
33
// internal header for replacing imgui rendering infrastructure
44

55
struct ImDrawData;
6-
namespace imgui {
7-
class Renderer {
6+
namespace imgui
7+
{
8+
class Renderer
9+
{
810
public:
9-
Renderer() = default;
11+
Renderer() = default;
1012
virtual ~Renderer() = default;
13+
//! Call after initial setup of imgui
14+
virtual void setup_imgui() = 0;
1115
//! prepare font files and other data
1216
//! This call may occur multiple times if the hardware context got lost.
1317
virtual void acquire_cached_resources() = 0;
1418
//! renders the ui data of ImGui - but does not flush/swap..
1519
virtual void render_imgui_data(ImDrawData& data) = 0;
20+
//! Preparation for next imgui render
21+
virtual void pre_frame() = 0;
1622
//! Use this call to perform buffer swapping or flushing
1723
virtual void finish_frame() = 0;
24+
//! hw buffer got resized
25+
virtual void resize(size_t w, size_t h) = 0;
1826
};
1927
} // namespace imgui

src/context.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ imgui::Context::Context(std::unique_ptr<SystemIntegration> integration,
1818
system->set_ui_call(std::move(fun));
1919

2020
system->setup_imgui();
21+
renderer->setup_imgui();
2122
renderer->acquire_cached_resources();
2223
style->apply_style();
2324
}

src/data_time_widgets.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ bool imgui::date_picker(const char* id, int& level, imgui::time_point& to_edit,
9292
const int days_last_mo = detail::days_in_month(this_mon == 0 ? last_year : this_year, last_mon);
9393
auto first_mo = std::chrono::system_clock::to_time_t(time_point{std::chrono::floor<months>(t.to_duration())});
9494
std::tm ts;
95+
#ifdef WIN32
96+
localtime_s(&ts, &first_mo);
97+
#else
9598
localtime_r(&first_mo, &ts);
99+
#endif
96100
const int first_wd = ts.tm_wday;
97101
// month year
98102
snprintf(buff, 32, "%s %d", names_mo[this_mon], this_year);

0 commit comments

Comments
 (0)