From 516c3dee802d67c87487572a2d44d8e2d285efd6 Mon Sep 17 00:00:00 2001 From: omar Date: Tue, 18 Jun 2019 11:28:26 +0200 Subject: [PATCH] Examples: SDL+DX11: Changelog, readme, batch files, fixed vcxproj, minor stylistic fixes + minor sync of other main.cpp files. (#2632) --- docs/CHANGELOG.txt | 6 +- examples/README.txt | 7 +++ examples/example_glfw_metal/main.mm | 1 + examples/example_glfw_opengl2/main.cpp | 1 + examples/example_glfw_opengl3/main.cpp | 1 + examples/example_glfw_vulkan/main.cpp | 1 + examples/example_glut_opengl2/main.cpp | 2 + examples/example_marmalade/main.cpp | 1 + .../example_sdl_directx11/build_win32.bat | 8 +++ .../example_sdl_directx11.vcxproj | 58 +++++++++++-------- examples/example_sdl_directx11/main.cpp | 19 +++--- examples/example_sdl_opengl2/main.cpp | 2 + examples/example_sdl_opengl3/main.cpp | 2 + examples/example_sdl_vulkan/main.cpp | 4 +- examples/example_win32_directx11/main.cpp | 1 + 15 files changed, 78 insertions(+), 36 deletions(-) create mode 100644 examples/example_sdl_directx11/build_win32.bat diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index d19dc5301..f575242fa 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -44,7 +44,11 @@ Breaking Changes: Other Changes: - Window: Fixed InnerClipRect right-most coordinates using wrong padding setting (introduced in 1.71). - ImDrawList: Fixed CloneOutput() helper crashing. (#1860) [@gviot] -- ImDrawListSlitter, ImDrawList::ChannelsSplit(), : Fixed an issue with merging draw commands between channel 0 and 1. (#2624) +- ImDrawListSlitter, ImDrawList::ChannelsSplit(), : Fixed an issue with merging draw commands between + channel 0 and 1. (#2624) +- Backends: SDL2: Added dummy ImGui_ImplSDL2_InitForD3D() function to make D3D support more visible. + (#2482, #2632) [@josiahmanson] +- Examples: Added SDL2+DirectX11 example application. (#2632, #2612, #2482) [@vincenthamm] ----------------------------------------------------------------------- diff --git a/examples/README.txt b/examples/README.txt index 116ef6b54..5028583bb 100644 --- a/examples/README.txt +++ b/examples/README.txt @@ -201,6 +201,7 @@ example_glfw_vulkan/ GLFW (Win32, Mac, Linux) + Vulkan example. = main.cpp + imgui_impl_glfw.cpp + imgui_impl_vulkan.cpp This is quite long and tedious, because: Vulkan. + For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp. example_glut_opengl2/ GLUT (e.g., FreeGLUT on Linux/Windows, GLUT framework on OSX) + OpenGL2. @@ -217,6 +218,11 @@ example_null This is used to quickly test compilation of core imgui files in as many setups as possible. Because this application doesn't create a window nor a graphic context, there's no graphics output. +example_sdl_directx11/ + SDL2 + DirectX11 example, Windows only. + = main.cpp + imgui_impl_sdl.cpp + imgui_impl_dx11.cpp + This to demonstrate usage of DirectX with SDL. + example_sdl_opengl2/ SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline). = main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp @@ -240,6 +246,7 @@ example_sdl_vulkan/ SDL2 (Win32, Mac, Linux, etc.) + Vulkan example. = main.cpp + imgui_impl_sdl.cpp + imgui_impl_vulkan.cpp This is quite long and tedious, because: Vulkan. + For this example, the main.cpp file exceptionally use helpers function from imgui_impl_vulkan.h/cpp. example_win32_directx9/ DirectX9 example, Windows only. diff --git a/examples/example_glfw_metal/main.mm b/examples/example_glfw_metal/main.mm index 3b162afbd..3a25a9de0 100644 --- a/examples/example_glfw_metal/main.mm +++ b/examples/example_glfw_metal/main.mm @@ -74,6 +74,7 @@ int main(int, char**) MTLRenderPassDescriptor *renderPassDescriptor = [MTLRenderPassDescriptor new]; + // Our state bool show_demo_window = true; bool show_another_window = false; float clear_color[4] = {0.45f, 0.55f, 0.60f, 1.00f}; diff --git a/examples/example_glfw_opengl2/main.cpp b/examples/example_glfw_opengl2/main.cpp index 57841ffa4..0a7aa3c3f 100644 --- a/examples/example_glfw_opengl2/main.cpp +++ b/examples/example_glfw_opengl2/main.cpp @@ -69,6 +69,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_glfw_opengl3/main.cpp b/examples/example_glfw_opengl3/main.cpp index dffd46c93..76174a1f8 100644 --- a/examples/example_glfw_opengl3/main.cpp +++ b/examples/example_glfw_opengl3/main.cpp @@ -112,6 +112,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_glfw_vulkan/main.cpp b/examples/example_glfw_vulkan/main.cpp index 2d1c4e004..fc3c1efb1 100644 --- a/examples/example_glfw_vulkan/main.cpp +++ b/examples/example_glfw_vulkan/main.cpp @@ -440,6 +440,7 @@ int main(int, char**) ImGui_ImplVulkan_DestroyFontUploadObjects(); } + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_glut_opengl2/main.cpp b/examples/example_glut_opengl2/main.cpp index 764ea092b..75e48ca2a 100644 --- a/examples/example_glut_opengl2/main.cpp +++ b/examples/example_glut_opengl2/main.cpp @@ -18,6 +18,7 @@ #pragma warning (disable: 4505) // unreferenced local function has been removed #endif +// Our state static bool show_demo_window = true; static bool show_another_window = false; static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); @@ -105,6 +106,7 @@ int main(int argc, char** argv) glutDisplayFunc(glut_display_func); // Setup Dear ImGui context + IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls diff --git a/examples/example_marmalade/main.cpp b/examples/example_marmalade/main.cpp index e844a4c9d..27a4acd9e 100644 --- a/examples/example_marmalade/main.cpp +++ b/examples/example_marmalade/main.cpp @@ -44,6 +44,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_sdl_directx11/build_win32.bat b/examples/example_sdl_directx11/build_win32.bat new file mode 100644 index 000000000..8fc702bb6 --- /dev/null +++ b/examples/example_sdl_directx11/build_win32.bat @@ -0,0 +1,8 @@ +@REM Build for Visual Studio compiler. Run your copy of vcvars32.bat or vcvarsall.bat to setup command-line compiler. +set OUT_DIR=Debug +set OUT_EXE=example_sdl_directx11 +set INCLUDES=/I.. /I..\.. /I%SDL2_DIR%\include /I "%WindowsSdkDir%Include\um" /I "%WindowsSdkDir%Include\shared" /I "%DXSDK_DIR%Include" +set SOURCES=main.cpp ..\imgui_impl_sdl.cpp ..\imgui_impl_dx11.cpp ..\..\imgui*.cpp +set LIBS=/libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib /LIBPATH:"%DXSDK_DIR%/Lib/x86" d3d11.lib d3dcompiler.lib +mkdir %OUT_DIR% +cl /nologo /Zi /MD %INCLUDES% %SOURCES% /Fe%OUT_DIR%/%OUT_EXE%.exe /Fo%OUT_DIR%/ /link %LIBS% /subsystem:console diff --git a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj index ce1c5749e..e28a5d251 100644 --- a/examples/example_sdl_directx11/example_sdl_directx11.vcxproj +++ b/examples/example_sdl_directx11/example_sdl_directx11.vcxproj @@ -20,7 +20,7 @@ {9E1987E3-1F19-45CA-B9C9-D31E791836D8} - example_win32_directx11 + example_sdl_directx11 8.1 example_sdl_directx11 @@ -28,28 +28,28 @@ Application true - Unicode - v140 + MultiByte + v110 Application true - Unicode - v140 + MultiByte + v110 Application false true - Unicode - v140 + MultiByte + v110 Application false true - Unicode - v140 + MultiByte + v110 @@ -70,43 +70,49 @@ $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ + $(IncludePath) $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ + $(IncludePath) $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ + $(IncludePath) $(ProjectDir)$(Configuration)\ $(ProjectDir)$(Configuration)\ + $(IncludePath) Level4 Disabled - ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) true + %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) - $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x86 Console + msvcrt.lib Level4 Disabled - ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) true + %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;%(AdditionalDependencies) - $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x64 Console + msvcrt.lib @@ -115,16 +121,18 @@ MaxSpeed true true - ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) false true true true + %SDL2_DIR%\lib\x86;$(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories) SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) - $(DXSDK_DIR)/Lib/x86;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x86 Console + + @@ -133,25 +141,20 @@ MaxSpeed true true - ..\..;..;%(AdditionalIncludeDirectories);$(SDL2_DIR)\include + ..\..;..;%SDL2_DIR%\include;%(AdditionalIncludeDirectories) false true true true + %SDL2_DIR%\lib\x64;$(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories) SDL2.lib;SDL2main.lib;d3d11.lib;d3dcompiler.lib;dxgi.lib;imm32.lib;%(AdditionalDependencies) - $(DXSDK_DIR)/Lib/x64;%(AdditionalLibraryDirectories);$(SDL2_DIR)\lib\x64 Console + + - - - - - - - @@ -161,6 +164,13 @@ + + + + + + + diff --git a/examples/example_sdl_directx11/main.cpp b/examples/example_sdl_directx11/main.cpp index bf470d78f..ae523fe90 100644 --- a/examples/example_sdl_directx11/main.cpp +++ b/examples/example_sdl_directx11/main.cpp @@ -1,4 +1,4 @@ -// dear imgui: standalone example application for SDL2 + OpenGL +// dear imgui: standalone example application for SDL2 + DirectX 11 // If you are new to dear imgui, see examples/README.txt and documentation at the top of imgui.cpp. // (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) @@ -22,6 +22,7 @@ void CleanupDeviceD3D(); void CreateRenderTarget(); void CleanupRenderTarget(); +// Main code int main(int, char**) { // Setup SDL @@ -31,14 +32,12 @@ int main(int, char**) return -1; } - // Create window with graphics context + // Setup window SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+DirectX11 example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags); - - SDL_SysWMinfo wmInfo; - SDL_VERSION(&wmInfo.version); - SDL_GetWindowWMInfo(window, &wmInfo); - + SDL_SysWMinfo wmInfo; + SDL_VERSION(&wmInfo.version); + SDL_GetWindowWMInfo(window, &wmInfo); HWND hwnd = (HWND)wmInfo.info.win.window; // Initialize Direct3D @@ -52,10 +51,8 @@ int main(int, char**) IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; - io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls + //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls - //io.ConfigViewportsNoAutoMerge = true; - //io.ConfigViewportsNoTaskBarIcon = true; // Setup Dear ImGui style ImGui::StyleColorsDark(); @@ -80,6 +77,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); @@ -168,6 +166,7 @@ int main(int, char**) } // Helper functions + bool CreateDeviceD3D(HWND hWnd) { // Setup swap chain diff --git a/examples/example_sdl_opengl2/main.cpp b/examples/example_sdl_opengl2/main.cpp index 7b3e853a4..1222c250c 100644 --- a/examples/example_sdl_opengl2/main.cpp +++ b/examples/example_sdl_opengl2/main.cpp @@ -13,6 +13,7 @@ #include #include +// Main code int main(int, char**) { // Setup SDL @@ -64,6 +65,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_sdl_opengl3/main.cpp b/examples/example_sdl_opengl3/main.cpp index 38b9ebd59..ae1ef5b32 100644 --- a/examples/example_sdl_opengl3/main.cpp +++ b/examples/example_sdl_opengl3/main.cpp @@ -22,6 +22,7 @@ #include IMGUI_IMPL_OPENGL_LOADER_CUSTOM #endif +// Main code int main(int, char**) { // Setup SDL @@ -104,6 +105,7 @@ int main(int, char**) //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); //IM_ASSERT(font != NULL); + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_sdl_vulkan/main.cpp b/examples/example_sdl_vulkan/main.cpp index 6ac67b824..12c262e9a 100644 --- a/examples/example_sdl_vulkan/main.cpp +++ b/examples/example_sdl_vulkan/main.cpp @@ -322,7 +322,7 @@ int main(int, char**) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) { printf("Error: %s\n", SDL_GetError()); - return 1; + return -1; } // Setup window @@ -353,6 +353,7 @@ int main(int, char**) SetupVulkanWindow(wd, surface, w, h); // Setup Dear ImGui context + IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls @@ -423,6 +424,7 @@ int main(int, char**) ImGui_ImplVulkan_DestroyFontUploadObjects(); } + // Our state bool show_demo_window = true; bool show_another_window = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); diff --git a/examples/example_win32_directx11/main.cpp b/examples/example_win32_directx11/main.cpp index 9523728d8..0a8f09b2c 100644 --- a/examples/example_win32_directx11/main.cpp +++ b/examples/example_win32_directx11/main.cpp @@ -146,6 +146,7 @@ int main(int, char**) //g_pSwapChain->Present(0, 0); // Present without vsync } + // Cleanup ImGui_ImplDX11_Shutdown(); ImGui_ImplWin32_Shutdown(); ImGui::DestroyContext();