mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-01 02:37:24 +01:00
Merge branch 'master' into docking
# Conflicts: # backends/imgui_impl_glfw.cpp # backends/imgui_impl_sdl.cpp # examples/example_emscripten_opengl3/main.cpp # examples/example_glfw_opengl2/main.cpp # examples/example_glfw_opengl3/main.cpp # examples/example_glfw_vulkan/main.cpp # examples/example_glut_opengl2/main.cpp # examples/example_sdl_directx11/main.cpp # examples/example_sdl_opengl2/main.cpp # examples/example_sdl_opengl3/main.cpp # examples/example_sdl_vulkan/main.cpp # examples/example_win32_directx10/main.cpp # examples/example_win32_directx11/main.cpp # examples/example_win32_directx12/main.cpp # examples/example_win32_directx9/main.cpp # imgui_demo.cpp
This commit is contained in:
commit
5386ddcd05
3
.gitignore
vendored
3
.gitignore
vendored
@ -40,7 +40,8 @@ xcuserdata
|
|||||||
examples/*.o.tmp
|
examples/*.o.tmp
|
||||||
examples/*.out.js
|
examples/*.out.js
|
||||||
examples/*.out.wasm
|
examples/*.out.wasm
|
||||||
examples/example_emscripten_opengl3/web/*
|
examples/example_glfw_opengl3/web/*
|
||||||
|
examples/example_sdl_opengl3/web/*
|
||||||
examples/example_emscripten_wgpu/web/*
|
examples/example_emscripten_wgpu/web/*
|
||||||
|
|
||||||
## JetBrains IDE artifacts
|
## JetBrains IDE artifacts
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
// 2023-02-01: Inputs: flipping both wheel axises when running on Emscripten's GLFW emulation. (#6096)
|
|
||||||
// 2023-01-18: Handle unsupported glfwGetVideoMode() call on e.g. Emscripten.
|
// 2023-01-18: Handle unsupported glfwGetVideoMode() call on e.g. Emscripten.
|
||||||
// 2023-01-04: Inputs: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, turns out they were faulty.
|
// 2023-01-04: Inputs: Fixed mods state on Linux when using Alt-GR text input (e.g. German keyboard layout), could lead to broken text input. Revert a 2022/01/17 change were we resumed using mods provided by GLFW, turns out they were faulty.
|
||||||
// 2022-11-22: Perform a dummy glfwGetError() read to cancel missing names with glfwGetKeyName(). (#5908)
|
// 2022-11-22: Perform a dummy glfwGetError() read to cancel missing names with glfwGetKeyName(). (#5908)
|
||||||
@ -319,13 +318,6 @@ void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yo
|
|||||||
if (bd->PrevUserCallbackScroll != nullptr && window == bd->Window)
|
if (bd->PrevUserCallbackScroll != nullptr && window == bd->Window)
|
||||||
bd->PrevUserCallbackScroll(window, xoffset, yoffset);
|
bd->PrevUserCallbackScroll(window, xoffset, yoffset);
|
||||||
|
|
||||||
#if defined(__EMSCRIPTEN__)
|
|
||||||
// Emscripten's GLFW emulation reports grossly mis-scaled and flipped scroll events.
|
|
||||||
// The scale is still currently incorrect, see #4019 #6096 for details.
|
|
||||||
xoffset /= -120.0f;
|
|
||||||
yoffset /= -120.0f;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.AddMouseWheelEvent((float)xoffset, (float)yoffset);
|
io.AddMouseWheelEvent((float)xoffset, (float)yoffset);
|
||||||
}
|
}
|
||||||
|
@ -114,6 +114,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Wunknown-warning-option" // warning: unknown warning group 'xxx'
|
||||||
#pragma GCC diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types
|
#pragma GCC diagnostic ignored "-Wcast-function-type" // warning: cast between incompatible function types
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
// 2023-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
|
||||||
|
// 2023-02-02: Removed SDL_MOUSEWHEEL value clamping, as values seem correct in latest Emscripten. (#4019)
|
||||||
// 2023-02-01: Flipping SDL_MOUSEWHEEL 'wheel.x' value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463)
|
// 2023-02-01: Flipping SDL_MOUSEWHEEL 'wheel.x' value to match other backends and offer consistent horizontal scrolling direction. (#4019, #6096, #1463)
|
||||||
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
// 2022-10-11: Using 'nullptr' instead of 'NULL' as per our switch to C++11.
|
||||||
// 2022-09-26: Inputs: Disable SDL 2.0.22 new "auto capture" (SDL_HINT_MOUSE_AUTO_CAPTURE) which prevents drag and drop across windows for multi-viewport support + don't capture when drag and dropping. (#5710)
|
// 2022-09-26: Inputs: Disable SDL 2.0.22 new "auto capture" (SDL_HINT_MOUSE_AUTO_CAPTURE) which prevents drag and drop across windows for multi-viewport support + don't capture when drag and dropping. (#5710)
|
||||||
@ -288,8 +289,8 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
|
|||||||
}
|
}
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
{
|
{
|
||||||
float wheel_x = (event->wheel.x < 0) ? 1.0f : (event->wheel.x > 0) ? -1.0f : 0.0f; // About the clamping and flipped axis: see #4019
|
float wheel_x = -(float)event->wheel.x;
|
||||||
float wheel_y = (event->wheel.y > 0) ? 1.0f : (event->wheel.y < 0) ? -1.0f : 0.0f;
|
float wheel_y = (float)event->wheel.y;
|
||||||
io.AddMouseWheelEvent(wheel_x, wheel_y);
|
io.AddMouseWheelEvent(wheel_x, wheel_y);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -112,8 +112,6 @@ Breaking changes:
|
|||||||
offer consistent horizontal scrolling direction. (#4019)
|
offer consistent horizontal scrolling direction. (#4019)
|
||||||
- Backends: SDL: flipping SDL_MOUSEWHEEL 'wheel.x' value to match other backends and
|
- Backends: SDL: flipping SDL_MOUSEWHEEL 'wheel.x' value to match other backends and
|
||||||
offer consistent horizontal scrolling direction. (#4019)
|
offer consistent horizontal scrolling direction. (#4019)
|
||||||
- Backends: GLFW+Emscripten: flipping both wheels axises + scaling magnitude down when
|
|
||||||
running on Emscripten's GLFW emulation. (#6096) [@topolarity]
|
|
||||||
- Shift+WheelY support on non-OSX machines was already correct. (#2424, #1463)
|
- Shift+WheelY support on non-OSX machines was already correct. (#2424, #1463)
|
||||||
(whereaas on OSX machines Shift+WheelY turns into WheelX at the OS level).
|
(whereaas on OSX machines Shift+WheelY turns into WheelX at the OS level).
|
||||||
- If you use a custom-backend, you should verify that:
|
- If you use a custom-backend, you should verify that:
|
||||||
@ -125,7 +123,7 @@ Breaking changes:
|
|||||||
- (*) both axises flipped On Windows for touchpad only when 'Settings->Touchpad->Down motion scrolls up' is set.
|
- (*) both axises flipped On Windows for touchpad only when 'Settings->Touchpad->Down motion scrolls up' is set.
|
||||||
- You can use 'Demo->Tools->Debug Log->IO" to visualize values submitted to Dear ImGui.
|
- You can use 'Demo->Tools->Debug Log->IO" to visualize values submitted to Dear ImGui.
|
||||||
- Known issues remaining with Emscripten:
|
- Known issues remaining with Emscripten:
|
||||||
- The magnitude of wheeling values on Emscripten setups is still mostly wrong. (#6096)
|
- The magnitude of wheeling values on Emscripten setups is still not great. (#6096)
|
||||||
- When running the Emscripten app on a Mac with a mouse, SHIFT+WheelY doesn't turn into WheelX.
|
- When running the Emscripten app on a Mac with a mouse, SHIFT+WheelY doesn't turn into WheelX.
|
||||||
This is because we don't know that we are running on Mac and apply our own Shift+swapping
|
This is because we don't know that we are running on Mac and apply our own Shift+swapping
|
||||||
on top of OSX' own swapping, so wheel axises are swapped twice. Emscripten apps may need
|
on top of OSX' own swapping, so wheel axises are swapped twice. Emscripten apps may need
|
||||||
@ -158,8 +156,14 @@ All changes:
|
|||||||
can exacerbate that. (#6114, #3644)
|
can exacerbate that. (#6114, #3644)
|
||||||
- Backends: OSX: Fixed scroll/wheel scaling for devices emitting events with
|
- Backends: OSX: Fixed scroll/wheel scaling for devices emitting events with
|
||||||
hasPreciseScrollingDeltas==false (e.g. non-Apple mices).
|
hasPreciseScrollingDeltas==false (e.g. non-Apple mices).
|
||||||
|
- Backends: SDL: Removed SDL_MOUSEWHEEL value clamping. (#4019, #6096, #6081)
|
||||||
|
Latest Emscripten seems to emit correct values.
|
||||||
- Backend: WebGPU: Fix building for latest WebGPU specs (remove implicit layout generation).
|
- Backend: WebGPU: Fix building for latest WebGPU specs (remove implicit layout generation).
|
||||||
(#6117, #4116, #3632) [@tonygrue, @bfierz]
|
(#6117, #4116, #3632) [@tonygrue, @bfierz]
|
||||||
|
- Examples: refactord all examples to use a "MainLoopStep()" function. This is in order
|
||||||
|
to be able to trivially make some compile with Emscripten. (#2492, #3699)
|
||||||
|
While not all examples are expected to compile on Emscripten, we try to keep all of them
|
||||||
|
as close as possible to each others.
|
||||||
- Examples: Win32: Fixed examples using RegisterClassW() since 1.89 to also call
|
- Examples: Win32: Fixed examples using RegisterClassW() since 1.89 to also call
|
||||||
DefWindowProcW() instead of DefWindowProc() so that title text are correctly converted
|
DefWindowProcW() instead of DefWindowProc() so that title text are correctly converted
|
||||||
when application is compiled without /DUNICODE. (#5725, #5961, #5975) [@markreidvfx]
|
when application is compiled without /DUNICODE. (#5725, #5961, #5975) [@markreidvfx]
|
||||||
|
@ -104,15 +104,10 @@ OSX + OpenGL2 example. <BR>
|
|||||||
(NB: imgui_impl_osx.mm is currently not as feature complete as other platforms backends.
|
(NB: imgui_impl_osx.mm is currently not as feature complete as other platforms backends.
|
||||||
You may prefer to use the GLFW Or SDL backends, which will also support Windows and Linux.)
|
You may prefer to use the GLFW Or SDL backends, which will also support Windows and Linux.)
|
||||||
|
|
||||||
[example_emscripten_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_emscripten_opengl3/) <BR>
|
|
||||||
Emcripten + SDL2 + OpenGL3+/ES2/ES3 example. <BR>
|
|
||||||
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp <BR>
|
|
||||||
Note that other examples based on SDL or GLFW + OpenGL could easily be modified to work with Emscripten.
|
|
||||||
We provide this to make the Emscripten differences obvious, and have them not pollute all other examples.
|
|
||||||
|
|
||||||
[example_emscripten_wgpu/](https://github.com/ocornut/imgui/blob/master/examples/example_emscripten_wgpu/) <BR>
|
[example_emscripten_wgpu/](https://github.com/ocornut/imgui/blob/master/examples/example_emscripten_wgpu/) <BR>
|
||||||
Emcripten + GLFW + WebGPU example. <BR>
|
Emcripten + GLFW + WebGPU example. <BR>
|
||||||
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_wgpu.cpp
|
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_wgpu.cpp
|
||||||
|
Note that the 'example_glfw_opengl3' and 'example_sdl_opengl3' examples also supports Emscripten!
|
||||||
|
|
||||||
[example_glfw_metal/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_metal/) <BR>
|
[example_glfw_metal/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_metal/) <BR>
|
||||||
GLFW (Mac) + Metal example. <BR>
|
GLFW (Mac) + Metal example. <BR>
|
||||||
@ -121,18 +116,18 @@ GLFW (Mac) + Metal example. <BR>
|
|||||||
[example_glfw_opengl2/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_opengl2/) <BR>
|
[example_glfw_opengl2/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_opengl2/) <BR>
|
||||||
GLFW + OpenGL2 example (legacy, fixed pipeline). <BR>
|
GLFW + OpenGL2 example (legacy, fixed pipeline). <BR>
|
||||||
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl2.cpp <BR>
|
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl2.cpp <BR>
|
||||||
**DO NOT USE THIS IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** <BR>
|
**DO NOT USE THIS IF YOUR CODE/ENGINE IS USING MODERN GL or WEBGL (SHADERS, VBO, VAO, etc.)** <BR>
|
||||||
This code is mostly provided as a reference to learn about Dear ImGui integration, because it is shorter.
|
This code is mostly provided as a reference to learn about Dear ImGui integration, because it is shorter.
|
||||||
If your code is using GL3+ context or any semi modern OpenGL calls, using this renderer is likely to
|
If your code is using GL3+ context or any semi modern GL calls, using this renderer is likely to
|
||||||
make things more complicated, will require your code to reset many OpenGL attributes to their initial
|
make things more complicated, will require your code to reset many GL attributes to their initial
|
||||||
state, and might confuse your GPU driver. One star, not recommended.
|
state, and might confuse your GPU driver. One star, not recommended.
|
||||||
|
|
||||||
[example_glfw_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_opengl3/) <BR>
|
[example_glfw_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_opengl3/) <BR>
|
||||||
GLFW (Win32, Mac, Linux) + OpenGL3+/ES2/ES3 example (modern, programmable pipeline). <BR>
|
GLFW (Win32, Mac, Linux) + OpenGL3+/ES2/ES3 example (modern, programmable pipeline). <BR>
|
||||||
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp <BR>
|
= main.cpp + imgui_impl_glfw.cpp + imgui_impl_opengl3.cpp <BR>
|
||||||
This uses more modern OpenGL calls and custom shaders. <BR>
|
This uses more modern GL calls and custom shaders.<BR>
|
||||||
This may actually also work with OpenGL 2.x contexts! <BR>
|
This support building with Emscripten and targetting WebGL.<BR>
|
||||||
Prefer using that if you are using modern OpenGL in your application (anything with shaders).
|
Prefer using that if you are using modern GL or WebGL in your application.
|
||||||
|
|
||||||
[example_glfw_vulkan/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_vulkan/) <BR>
|
[example_glfw_vulkan/](https://github.com/ocornut/imgui/blob/master/examples/example_glfw_vulkan/) <BR>
|
||||||
GLFW (Win32, Mac, Linux) + Vulkan example. <BR>
|
GLFW (Win32, Mac, Linux) + Vulkan example. <BR>
|
||||||
@ -163,17 +158,18 @@ SDL2 (Mac) + Metal example. <BR>
|
|||||||
[example_sdl_opengl2/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_opengl2/) <BR>
|
[example_sdl_opengl2/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_opengl2/) <BR>
|
||||||
SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline). <BR>
|
SDL2 (Win32, Mac, Linux etc.) + OpenGL example (legacy, fixed pipeline). <BR>
|
||||||
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp <BR>
|
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl2.cpp <BR>
|
||||||
**DO NOT USE OPENGL2 CODE IF YOUR CODE/ENGINE IS USING MODERN OPENGL (SHADERS, VBO, VAO, etc.)** <BR>
|
**DO NOT USE OPENGL2 CODE IF YOUR CODE/ENGINE IS USING GL OR WEBGL (SHADERS, VBO, VAO, etc.)** <BR>
|
||||||
This code is mostly provided as a reference to learn about Dear ImGui integration, because it is shorter.
|
This code is mostly provided as a reference to learn about Dear ImGui integration, because it is shorter.
|
||||||
If your code is using GL3+ context or any semi modern OpenGL calls, using this renderer is likely to
|
If your code is using GL3+ context or any semi modern GL calls, using this renderer is likely to
|
||||||
make things more complicated, will require your code to reset many OpenGL attributes to their initial
|
make things more complicated, will require your code to reset many GL attributes to their initial
|
||||||
state, and might confuse your GPU driver. One star, not recommended.
|
state, and might confuse your GPU driver. One star, not recommended.
|
||||||
|
|
||||||
[example_sdl_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_opengl3/) <BR>
|
[example_sdl_opengl3/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_opengl3/) <BR>
|
||||||
SDL2 (Win32, Mac, Linux, etc.) + OpenGL3+/ES2/ES3 example. <BR>
|
SDL2 (Win32, Mac, Linux, etc.) + OpenGL3+/ES2/ES3 example. <BR>
|
||||||
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp <BR>
|
= main.cpp + imgui_impl_sdl.cpp + imgui_impl_opengl3.cpp <BR>
|
||||||
This uses more modern OpenGL calls and custom shaders. <BR>
|
This uses more modern GL calls and custom shaders. <BR>
|
||||||
This may actually also work with OpenGL 2.x contexts! <BR>
|
This support building with Emscripten and targetting WebGL.<BR>
|
||||||
|
Prefer using that if you are using modern GL or WebGL in your application.
|
||||||
|
|
||||||
[example_sdl_sdlrenderer/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_sdlrenderer/) <BR>
|
[example_sdl_sdlrenderer/](https://github.com/ocornut/imgui/blob/master/examples/example_sdl_sdlrenderer/) <BR>
|
||||||
SDL2 (Win32, Mac, Linux, etc.) + SDL_Renderer (most graphics backends are supported underneath) <BR>
|
SDL2 (Win32, Mac, Linux, etc.) + SDL_Renderer (most graphics backends are supported underneath) <BR>
|
||||||
|
@ -16,6 +16,10 @@
|
|||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_impl_allegro5.h"
|
#include "imgui_impl_allegro5.h"
|
||||||
|
|
||||||
|
// Forward declarations of helper functions
|
||||||
|
bool MainLoopStep(ALLEGRO_DISPLAY* display, ALLEGRO_EVENT_QUEUE* queue);
|
||||||
|
|
||||||
|
// Main code
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Setup Allegro
|
// Setup Allegro
|
||||||
@ -23,6 +27,8 @@ int main(int, char**)
|
|||||||
al_install_keyboard();
|
al_install_keyboard();
|
||||||
al_install_mouse();
|
al_install_mouse();
|
||||||
al_init_primitives_addon();
|
al_init_primitives_addon();
|
||||||
|
|
||||||
|
// Create window with graphics context and event queue
|
||||||
al_set_new_display_flags(ALLEGRO_RESIZABLE);
|
al_set_new_display_flags(ALLEGRO_RESIZABLE);
|
||||||
ALLEGRO_DISPLAY* display = al_create_display(1280, 720);
|
ALLEGRO_DISPLAY* display = al_create_display(1280, 720);
|
||||||
al_set_window_title(display, "Dear ImGui Allegro 5 example");
|
al_set_window_title(display, "Dear ImGui Allegro 5 example");
|
||||||
@ -61,25 +67,36 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//IM_ASSERT(font != NULL);
|
||||||
|
|
||||||
bool show_demo_window = true;
|
|
||||||
bool show_another_window = false;
|
|
||||||
ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool running = true;
|
while (true)
|
||||||
while (running)
|
{
|
||||||
|
if (!MainLoopStep(display, queue))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplAllegro5_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
al_destroy_event_queue(queue);
|
||||||
|
al_destroy_display(display);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainLoopStep(ALLEGRO_DISPLAY* display, ALLEGRO_EVENT_QUEUE* queue)
|
||||||
{
|
{
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
// Poll and handle events (inputs, window resize, etc.)
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
bool done = false;
|
||||||
ALLEGRO_EVENT ev;
|
ALLEGRO_EVENT ev;
|
||||||
while (al_get_next_event(queue, &ev))
|
while (al_get_next_event(queue, &ev))
|
||||||
{
|
{
|
||||||
ImGui_ImplAllegro5_ProcessEvent(&ev);
|
ImGui_ImplAllegro5_ProcessEvent(&ev);
|
||||||
if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
|
if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
|
||||||
running = false;
|
done = true;
|
||||||
if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
|
if (ev.type == ALLEGRO_EVENT_DISPLAY_RESIZE)
|
||||||
{
|
{
|
||||||
ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
ImGui_ImplAllegro5_InvalidateDeviceObjects();
|
||||||
@ -87,11 +104,19 @@ int main(int, char**)
|
|||||||
ImGui_ImplAllegro5_CreateDeviceObjects();
|
ImGui_ImplAllegro5_CreateDeviceObjects();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (done)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
ImGui_ImplAllegro5_NewFrame();
|
ImGui_ImplAllegro5_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -134,13 +159,6 @@ int main(int, char**)
|
|||||||
al_clear_to_color(al_map_rgba_f(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w));
|
al_clear_to_color(al_map_rgba_f(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w));
|
||||||
ImGui_ImplAllegro5_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplAllegro5_RenderDrawData(ImGui::GetDrawData());
|
||||||
al_flip_display();
|
al_flip_display();
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup
|
return true;
|
||||||
ImGui_ImplAllegro5_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
al_destroy_event_queue(queue);
|
|
||||||
al_destroy_display(display);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -21,11 +21,72 @@ static char g_LogTag[] = "ImGuiExample";
|
|||||||
static std::string g_IniFilename = "";
|
static std::string g_IniFilename = "";
|
||||||
|
|
||||||
// Forward declarations of helper functions
|
// Forward declarations of helper functions
|
||||||
|
static void Init(struct android_app* app);
|
||||||
|
static void Shutdown();
|
||||||
|
static void MainLoopStep();
|
||||||
static int ShowSoftKeyboardInput();
|
static int ShowSoftKeyboardInput();
|
||||||
static int PollUnicodeChars();
|
static int PollUnicodeChars();
|
||||||
static int GetAssetData(const char* filename, void** out_data);
|
static int GetAssetData(const char* filename, void** out_data);
|
||||||
|
|
||||||
void init(struct android_app* app)
|
// Main code
|
||||||
|
static void handleAppCmd(struct android_app* app, int32_t appCmd)
|
||||||
|
{
|
||||||
|
switch (appCmd)
|
||||||
|
{
|
||||||
|
case APP_CMD_SAVE_STATE:
|
||||||
|
break;
|
||||||
|
case APP_CMD_INIT_WINDOW:
|
||||||
|
Init(app);
|
||||||
|
break;
|
||||||
|
case APP_CMD_TERM_WINDOW:
|
||||||
|
Shutdown();
|
||||||
|
break;
|
||||||
|
case APP_CMD_GAINED_FOCUS:
|
||||||
|
case APP_CMD_LOST_FOCUS:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t handleInputEvent(struct android_app* app, AInputEvent* inputEvent)
|
||||||
|
{
|
||||||
|
return ImGui_ImplAndroid_HandleInputEvent(inputEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void android_main(struct android_app* app)
|
||||||
|
{
|
||||||
|
app->onAppCmd = handleAppCmd;
|
||||||
|
app->onInputEvent = handleInputEvent;
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
int out_events;
|
||||||
|
struct android_poll_source* out_data;
|
||||||
|
|
||||||
|
// Poll all events. If the app is not visible, this loop blocks until g_Initialized == true.
|
||||||
|
while (ALooper_pollAll(g_Initialized ? 0 : -1, NULL, &out_events, (void**)&out_data) >= 0)
|
||||||
|
{
|
||||||
|
// Process one event
|
||||||
|
if (out_data != NULL)
|
||||||
|
out_data->process(app, out_data);
|
||||||
|
|
||||||
|
// Exit the app by returning from within the infinite loop
|
||||||
|
if (app->destroyRequested != 0)
|
||||||
|
{
|
||||||
|
// shutdown() should have been called already while processing the
|
||||||
|
// app command APP_CMD_TERM_WINDOW. But we play save here
|
||||||
|
if (!g_Initialized)
|
||||||
|
Shutdown();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initiate a new frame
|
||||||
|
MainLoopStep();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init(struct android_app* app)
|
||||||
{
|
{
|
||||||
if (g_Initialized)
|
if (g_Initialized)
|
||||||
return;
|
return;
|
||||||
@ -125,13 +186,14 @@ void init(struct android_app* app)
|
|||||||
g_Initialized = true;
|
g_Initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tick()
|
void MainLoopStep()
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
if (g_EglDisplay == EGL_NO_DISPLAY)
|
if (g_EglDisplay == EGL_NO_DISPLAY)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Our state
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
static bool show_demo_window = true;
|
static bool show_demo_window = true;
|
||||||
static bool show_another_window = false;
|
static bool show_another_window = false;
|
||||||
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
@ -197,7 +259,7 @@ void tick()
|
|||||||
eglSwapBuffers(g_EglDisplay, g_EglSurface);
|
eglSwapBuffers(g_EglDisplay, g_EglSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void shutdown()
|
void Shutdown()
|
||||||
{
|
{
|
||||||
if (!g_Initialized)
|
if (!g_Initialized)
|
||||||
return;
|
return;
|
||||||
@ -228,63 +290,7 @@ void shutdown()
|
|||||||
g_Initialized = false;
|
g_Initialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handleAppCmd(struct android_app* app, int32_t appCmd)
|
// Helper functions
|
||||||
{
|
|
||||||
switch (appCmd)
|
|
||||||
{
|
|
||||||
case APP_CMD_SAVE_STATE:
|
|
||||||
break;
|
|
||||||
case APP_CMD_INIT_WINDOW:
|
|
||||||
init(app);
|
|
||||||
break;
|
|
||||||
case APP_CMD_TERM_WINDOW:
|
|
||||||
shutdown();
|
|
||||||
break;
|
|
||||||
case APP_CMD_GAINED_FOCUS:
|
|
||||||
break;
|
|
||||||
case APP_CMD_LOST_FOCUS:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t handleInputEvent(struct android_app* app, AInputEvent* inputEvent)
|
|
||||||
{
|
|
||||||
return ImGui_ImplAndroid_HandleInputEvent(inputEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
void android_main(struct android_app* app)
|
|
||||||
{
|
|
||||||
app->onAppCmd = handleAppCmd;
|
|
||||||
app->onInputEvent = handleInputEvent;
|
|
||||||
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
int out_events;
|
|
||||||
struct android_poll_source* out_data;
|
|
||||||
|
|
||||||
// Poll all events. If the app is not visible, this loop blocks until g_Initialized == true.
|
|
||||||
while (ALooper_pollAll(g_Initialized ? 0 : -1, NULL, &out_events, (void**)&out_data) >= 0)
|
|
||||||
{
|
|
||||||
// Process one event
|
|
||||||
if (out_data != NULL)
|
|
||||||
out_data->process(app, out_data);
|
|
||||||
|
|
||||||
// Exit the app by returning from within the infinite loop
|
|
||||||
if (app->destroyRequested != 0)
|
|
||||||
{
|
|
||||||
// shutdown() should have been called already while processing the
|
|
||||||
// app command APP_CMD_TERM_WINDOW. But we play save here
|
|
||||||
if (!g_Initialized)
|
|
||||||
shutdown();
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initiate a new frame
|
|
||||||
tick();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Unfortunately, there is no way to show the on-screen input from native code.
|
// Unfortunately, there is no way to show the on-screen input from native code.
|
||||||
// Therefore, we call ShowSoftKeyboardInput() of the main activity implemented in MainActivity.kt via JNI.
|
// Therefore, we call ShowSoftKeyboardInput() of the main activity implemented in MainActivity.kt via JNI.
|
||||||
|
@ -1,167 +0,0 @@
|
|||||||
// Dear ImGui: standalone example application for Emscripten, using GLFW + OpenGL3
|
|
||||||
// (Emscripten is a C++-to-javascript compiler, used to publish executables for the web. See https://emscripten.org/)
|
|
||||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
|
||||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
|
||||||
|
|
||||||
// This is mostly the same code as the GLFW + OpenGL3 example, simply with the modifications needed to run on Emscripten.
|
|
||||||
// It is possible to combine both code into a single source file that will compile properly on Desktop and using Emscripten.
|
|
||||||
// See https://github.com/ocornut/imgui/pull/2492 as an example on how to do just that.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#include "imgui_impl_glfw.h"
|
|
||||||
#include "imgui_impl_opengl3.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <emscripten.h>
|
|
||||||
#define GL_SILENCE_DEPRECATION
|
|
||||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
|
||||||
#include <GLES2/gl2.h>
|
|
||||||
#endif
|
|
||||||
#include <GLFW/glfw3.h> // Will drag system OpenGL headers
|
|
||||||
|
|
||||||
// Emscripten requires to have full control over the main loop. We're going to store our GLFW book-keeping variables globally.
|
|
||||||
// Having a single function that acts as a loop prevents us to store state in the stack of said function. So we need some location for this.
|
|
||||||
GLFWwindow* g_Window = NULL;
|
|
||||||
|
|
||||||
static void glfw_error_callback(int error, const char* description)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
|
|
||||||
}
|
|
||||||
|
|
||||||
// For clarity, our main loop code is declared at the end.
|
|
||||||
static void main_loop(void*);
|
|
||||||
|
|
||||||
int main(int, char**)
|
|
||||||
{
|
|
||||||
// Setup window
|
|
||||||
glfwSetErrorCallback(glfw_error_callback);
|
|
||||||
if (!glfwInit())
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// For the browser using Emscripten, we are going to use WebGL1 with GL ES2. See the Makefile. for requirement details.
|
|
||||||
// It is very likely the generated file won't work in many browsers. Firefox is the only sure bet, but I have successfully
|
|
||||||
// run this code on Chrome for Android for example.
|
|
||||||
const char* glsl_version = "#version 100";
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
|
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
|
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
|
|
||||||
|
|
||||||
// Create window with graphics context
|
|
||||||
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+Emscripten example", NULL, NULL);
|
|
||||||
if (window == NULL)
|
|
||||||
return 1;
|
|
||||||
glfwMakeContextCurrent(window);
|
|
||||||
glfwSwapInterval(1); // Enable vsync
|
|
||||||
g_Window = window;
|
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
ImGui::CreateContext();
|
|
||||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
|
||||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
|
||||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
|
||||||
|
|
||||||
// For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file.
|
|
||||||
// You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
|
|
||||||
io.IniFilename = NULL;
|
|
||||||
|
|
||||||
// Setup Dear ImGui style
|
|
||||||
ImGui::StyleColorsDark();
|
|
||||||
//ImGui::StyleColorsLight();
|
|
||||||
|
|
||||||
// Setup Platform/Renderer backends
|
|
||||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
|
||||||
ImGui_ImplOpenGL3_Init(glsl_version);
|
|
||||||
|
|
||||||
// Load Fonts
|
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
|
||||||
// - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
|
||||||
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details.
|
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
|
||||||
// - Emscripten allows preloading a file or folder to be accessible at runtime. See Makefile for details.
|
|
||||||
//io.Fonts->AddFontDefault();
|
|
||||||
#ifndef IMGUI_DISABLE_FILE_FUNCTIONS
|
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/segoeui.ttf", 18.0f);
|
|
||||||
io.Fonts->AddFontFromFileTTF("fonts/DroidSans.ttf", 16.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/Roboto-Medium.ttf", 16.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/Cousine-Regular.ttf", 15.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/ProggyTiny.ttf", 10.0f);
|
|
||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("fonts/ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
|
||||||
//IM_ASSERT(font != NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// This function call won't return, and will engage in an infinite loop, processing events from the browser, and dispatching them.
|
|
||||||
emscripten_set_main_loop_arg(main_loop, NULL, 0, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void main_loop(void* arg)
|
|
||||||
{
|
|
||||||
IM_UNUSED(arg); // We can pass this argument as the second parameter of emscripten_set_main_loop_arg(), but we don't use that.
|
|
||||||
|
|
||||||
// Our state (make them static = more or less global) as a convenience to keep the example terse.
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
|
||||||
glfwPollEvents();
|
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
|
||||||
ImGui_ImplGlfw_NewFrame();
|
|
||||||
ImGui::NewFrame();
|
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
|
||||||
if (show_demo_window)
|
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
|
||||||
|
|
||||||
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window.
|
|
||||||
{
|
|
||||||
static float f = 0.0f;
|
|
||||||
static int counter = 0;
|
|
||||||
|
|
||||||
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
|
||||||
|
|
||||||
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
|
||||||
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
|
||||||
ImGui::Checkbox("Another Window", &show_another_window);
|
|
||||||
|
|
||||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
|
||||||
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
|
|
||||||
|
|
||||||
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
|
||||||
counter++;
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Text("counter = %d", counter);
|
|
||||||
|
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Show another simple window.
|
|
||||||
if (show_another_window)
|
|
||||||
{
|
|
||||||
ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
|
|
||||||
ImGui::Text("Hello from another window!");
|
|
||||||
if (ImGui::Button("Close Me"))
|
|
||||||
show_another_window = false;
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rendering
|
|
||||||
ImGui::Render();
|
|
||||||
int display_w, display_h;
|
|
||||||
glfwGetFramebufferSize(g_Window, &display_w, &display_h);
|
|
||||||
glViewport(0, 0, display_w, display_h);
|
|
||||||
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
||||||
|
|
||||||
glfwSwapBuffers(g_Window);
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en-us">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>
|
|
||||||
<title>Dear ImGui GLFW+Emscripten example</title>
|
|
||||||
<style>
|
|
||||||
body { margin: 0; background-color: black }
|
|
||||||
.emscripten {
|
|
||||||
position: absolute;
|
|
||||||
top: 0px;
|
|
||||||
left: 0px;
|
|
||||||
margin: 0px;
|
|
||||||
border: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
overflow: hidden;
|
|
||||||
display: block;
|
|
||||||
image-rendering: optimizeSpeed;
|
|
||||||
image-rendering: -moz-crisp-edges;
|
|
||||||
image-rendering: -o-crisp-edges;
|
|
||||||
image-rendering: -webkit-optimize-contrast;
|
|
||||||
image-rendering: optimize-contrast;
|
|
||||||
image-rendering: crisp-edges;
|
|
||||||
image-rendering: pixelated;
|
|
||||||
-ms-interpolation-mode: nearest-neighbor;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
|
|
||||||
<script type='text/javascript'>
|
|
||||||
var Module = {
|
|
||||||
preRun: [],
|
|
||||||
postRun: [],
|
|
||||||
print: (function() {
|
|
||||||
return function(text) {
|
|
||||||
text = Array.prototype.slice.call(arguments).join(' ');
|
|
||||||
console.log(text);
|
|
||||||
};
|
|
||||||
})(),
|
|
||||||
printErr: function(text) {
|
|
||||||
text = Array.prototype.slice.call(arguments).join(' ');
|
|
||||||
console.error(text);
|
|
||||||
},
|
|
||||||
canvas: (function() {
|
|
||||||
var canvas = document.getElementById('canvas');
|
|
||||||
//canvas.addEventListener("webglcontextlost", function(e) { alert('FIXME: WebGL context lost, please reload the page'); e.preventDefault(); }, false);
|
|
||||||
return canvas;
|
|
||||||
})(),
|
|
||||||
setStatus: function(text) {
|
|
||||||
console.log("status: " + text);
|
|
||||||
},
|
|
||||||
monitorRunDependencies: function(left) {
|
|
||||||
// no run dependencies to log
|
|
||||||
}
|
|
||||||
};
|
|
||||||
window.onerror = function() {
|
|
||||||
console.log("onerror: " + event);
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
{{{ SCRIPT }}}
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,26 +0,0 @@
|
|||||||
## How to Build
|
|
||||||
|
|
||||||
- You need to install Emscripten from https://emscripten.org/docs/getting_started/downloads.html, and have the environment variables set, as described in https://emscripten.org/docs/getting_started/downloads.html#installation-instructions
|
|
||||||
|
|
||||||
- Depending on your configuration, in Windows you may need to run `emsdk/emsdk_env.bat` in your console to access the Emscripten command-line tools.
|
|
||||||
|
|
||||||
- You may also refer to our [Continuous Integration setup](https://github.com/ocornut/imgui/tree/master/.github/workflows) for Emscripten setup.
|
|
||||||
|
|
||||||
- Then build using `make` while in the `example_emscripten_opengl3/` directory.
|
|
||||||
|
|
||||||
## How to Run
|
|
||||||
|
|
||||||
To run on a local machine:
|
|
||||||
- `make serve` will use Python3 to spawn a local webserver, you can then browse http://localhost:8000 to access your build.
|
|
||||||
- Otherwise, generally you will need a local webserver:
|
|
||||||
- Quoting [https://emscripten.org/docs/getting_started](https://emscripten.org/docs/getting_started/Tutorial.html#generating-html):<br>
|
|
||||||
_"Unfortunately several browsers (including Chrome, Safari, and Internet Explorer) do not support file:// [XHR](https://emscripten.org/docs/site/glossary.html#term-xhr) requests, and can’t load extra files needed by the HTML (like a .wasm file, or packaged file data as mentioned lower down). For these browsers you’ll need to serve the files using a [local webserver](https://emscripten.org/docs/getting_started/FAQ.html#faq-local-webserver) and then open http://localhost:8000/hello.html."_
|
|
||||||
- Emscripten SDK has a handy `emrun` command: `emrun web/example_emscripten_opengl3.html --browser firefox` which will spawn a temporary local webserver (in Firefox). See https://emscripten.org/docs/compiling/Running-html-files-with-emrun.html for details.
|
|
||||||
- You may use Python 3 builtin webserver: `python -m http.server -d web` (this is what `make serve` uses).
|
|
||||||
- You may use Python 2 builtin webserver: `cd web && python -m SimpleHTTPServer`.
|
|
||||||
- If you are accessing the files over a network, certain browsers, such as Firefox, will restrict Gamepad API access to secure contexts only (e.g. https only).
|
|
||||||
|
|
||||||
## Obsolete features:
|
|
||||||
|
|
||||||
- Emscripten 2.0 (August 2020) obsoleted the fastcomp backend, only llvm is supported.
|
|
||||||
- Emscripten 1.39.0 (October 2019) obsoleted the `BINARYEN_TRAP_MODE=clamp` compilation flag which was required with version older than 1.39.0 to avoid rendering artefacts. See [#2877](https://github.com/ocornut/imgui/issues/2877) for details. If you use an older version, uncomment this line in the Makefile: `#EMS += -s BINARYEN_TRAP_MODE=clamp`
|
|
@ -1,177 +0,0 @@
|
|||||||
// Dear ImGui: standalone example application for Emscripten, using SDL2 + OpenGL3
|
|
||||||
// (Emscripten is a C++-to-javascript compiler, used to publish executables for the web. See https://emscripten.org/)
|
|
||||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
|
||||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
|
||||||
|
|
||||||
// This is mostly the same code as the SDL2 + OpenGL3 example, simply with the modifications needed to run on Emscripten.
|
|
||||||
// It is possible to combine both code into a single source file that will compile properly on Desktop and using Emscripten.
|
|
||||||
// See https://github.com/ocornut/imgui/pull/2492 as an example on how to do just that.
|
|
||||||
|
|
||||||
#include "imgui.h"
|
|
||||||
#include "imgui_impl_sdl.h"
|
|
||||||
#include "imgui_impl_opengl3.h"
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <emscripten.h>
|
|
||||||
#include <SDL.h>
|
|
||||||
#include <SDL_opengles2.h>
|
|
||||||
|
|
||||||
// Emscripten requires to have full control over the main loop. We're going to store our SDL book-keeping variables globally.
|
|
||||||
// Having a single function that acts as a loop prevents us to store state in the stack of said function. So we need some location for this.
|
|
||||||
SDL_Window* g_Window = NULL;
|
|
||||||
SDL_GLContext g_GLContext = NULL;
|
|
||||||
|
|
||||||
// For clarity, our main loop code is declared at the end.
|
|
||||||
static void main_loop(void*);
|
|
||||||
|
|
||||||
int main(int, char**)
|
|
||||||
{
|
|
||||||
// Setup SDL
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
|
||||||
{
|
|
||||||
printf("Error: %s\n", SDL_GetError());
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// For the browser using Emscripten, we are going to use WebGL1 with GL ES2. See the Makefile. for requirement details.
|
|
||||||
// It is very likely the generated file won't work in many browsers. Firefox is the only sure bet, but I have successfully
|
|
||||||
// run this code on Chrome for Android for example.
|
|
||||||
const char* glsl_version = "#version 100";
|
|
||||||
//const char* glsl_version = "#version 300 es";
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
|
||||||
|
|
||||||
// Create window with graphics context
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
|
||||||
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
|
||||||
SDL_DisplayMode current;
|
|
||||||
SDL_GetCurrentDisplayMode(0, ¤t);
|
|
||||||
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
|
||||||
g_Window = SDL_CreateWindow("Dear ImGui SDL+Emscripten example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
|
|
||||||
g_GLContext = SDL_GL_CreateContext(g_Window);
|
|
||||||
if (!g_GLContext)
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Failed to initialize WebGL context!\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
|
||||||
IMGUI_CHECKVERSION();
|
|
||||||
ImGui::CreateContext();
|
|
||||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
|
||||||
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
|
||||||
|
|
||||||
// For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file.
|
|
||||||
// You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
|
|
||||||
io.IniFilename = NULL;
|
|
||||||
|
|
||||||
// Setup Dear ImGui style
|
|
||||||
ImGui::StyleColorsDark();
|
|
||||||
//ImGui::StyleColorsLight();
|
|
||||||
|
|
||||||
// Setup Platform/Renderer backends
|
|
||||||
ImGui_ImplSDL2_InitForOpenGL(g_Window, g_GLContext);
|
|
||||||
ImGui_ImplOpenGL3_Init(glsl_version);
|
|
||||||
|
|
||||||
// Load Fonts
|
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
|
||||||
// - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
|
||||||
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details.
|
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
|
||||||
// - Emscripten allows preloading a file or folder to be accessible at runtime. See Makefile for details.
|
|
||||||
//io.Fonts->AddFontDefault();
|
|
||||||
#ifndef IMGUI_DISABLE_FILE_FUNCTIONS
|
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/segoeui.ttf", 18.0f);
|
|
||||||
io.Fonts->AddFontFromFileTTF("fonts/DroidSans.ttf", 16.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/Roboto-Medium.ttf", 16.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/Cousine-Regular.ttf", 15.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("fonts/ProggyTiny.ttf", 10.0f);
|
|
||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("fonts/ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
|
||||||
//IM_ASSERT(font != NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// This function call won't return, and will engage in an infinite loop, processing events from the browser, and dispatching them.
|
|
||||||
emscripten_set_main_loop_arg(main_loop, NULL, 0, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void main_loop(void* arg)
|
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
IM_UNUSED(arg); // We can pass this argument as the second parameter of emscripten_set_main_loop_arg(), but we don't use that.
|
|
||||||
|
|
||||||
// Our state (make them static = more or less global) as a convenience to keep the example terse.
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
|
||||||
SDL_Event event;
|
|
||||||
while (SDL_PollEvent(&event))
|
|
||||||
{
|
|
||||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
|
||||||
// Capture events here, based on io.WantCaptureMouse and io.WantCaptureKeyboard
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
|
||||||
ImGui_ImplSDL2_NewFrame();
|
|
||||||
ImGui::NewFrame();
|
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
|
||||||
if (show_demo_window)
|
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
|
||||||
|
|
||||||
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window.
|
|
||||||
{
|
|
||||||
static float f = 0.0f;
|
|
||||||
static int counter = 0;
|
|
||||||
|
|
||||||
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
|
||||||
|
|
||||||
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
|
||||||
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
|
||||||
ImGui::Checkbox("Another Window", &show_another_window);
|
|
||||||
|
|
||||||
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
|
||||||
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
|
|
||||||
|
|
||||||
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
|
||||||
counter++;
|
|
||||||
ImGui::SameLine();
|
|
||||||
ImGui::Text("counter = %d", counter);
|
|
||||||
|
|
||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 3. Show another simple window.
|
|
||||||
if (show_another_window)
|
|
||||||
{
|
|
||||||
ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
|
|
||||||
ImGui::Text("Hello from another window!");
|
|
||||||
if (ImGui::Button("Close Me"))
|
|
||||||
show_another_window = false;
|
|
||||||
ImGui::End();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rendering
|
|
||||||
ImGui::Render();
|
|
||||||
SDL_GL_MakeCurrent(g_Window, g_GLContext);
|
|
||||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
|
||||||
glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
|
||||||
SDL_GL_SwapWindow(g_Window);
|
|
||||||
}
|
|
@ -21,17 +21,13 @@ static WGPUSwapChain wgpu_swap_chain = NULL;
|
|||||||
static int wgpu_swap_chain_width = 0;
|
static int wgpu_swap_chain_width = 0;
|
||||||
static int wgpu_swap_chain_height = 0;
|
static int wgpu_swap_chain_height = 0;
|
||||||
|
|
||||||
// States tracked across render frames
|
|
||||||
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);
|
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
static bool init_wgpu();
|
static void MainLoopStep(void* window);
|
||||||
static void main_loop(void* window);
|
static bool InitWGPU();
|
||||||
static void print_glfw_error(int error, const char* description);
|
static void print_glfw_error(int error, const char* description);
|
||||||
static void print_wgpu_error(WGPUErrorType error_type, const char* message, void*);
|
static void print_wgpu_error(WGPUErrorType error_type, const char* message, void*);
|
||||||
|
|
||||||
|
// Main code
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
glfwSetErrorCallback(print_glfw_error);
|
glfwSetErrorCallback(print_glfw_error);
|
||||||
@ -39,9 +35,8 @@ int main(int, char**)
|
|||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
// Make sure GLFW does not initialize any graphics context.
|
// Make sure GLFW does not initialize any graphics context.
|
||||||
// This needs to be done explicitly later
|
// This needs to be done explicitly later.
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
|
|
||||||
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+WebGPU example", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+WebGPU example", NULL, NULL);
|
||||||
if (!window)
|
if (!window)
|
||||||
{
|
{
|
||||||
@ -50,7 +45,7 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the WebGPU environment
|
// Initialize the WebGPU environment
|
||||||
if (!init_wgpu())
|
if (!InitWGPU())
|
||||||
{
|
{
|
||||||
if (window)
|
if (window)
|
||||||
glfwDestroyWindow(window);
|
glfwDestroyWindow(window);
|
||||||
@ -101,12 +96,12 @@ int main(int, char**)
|
|||||||
// This function will directly return and exit the main function.
|
// This function will directly return and exit the main function.
|
||||||
// Make sure that no required objects get cleaned up.
|
// Make sure that no required objects get cleaned up.
|
||||||
// This way we can use the browsers 'requestAnimationFrame' to control the rendering.
|
// This way we can use the browsers 'requestAnimationFrame' to control the rendering.
|
||||||
emscripten_set_main_loop_arg(main_loop, window, 0, false);
|
emscripten_set_main_loop_arg(MainLoopStep, window, 0, false);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool init_wgpu()
|
static bool InitWGPU()
|
||||||
{
|
{
|
||||||
wgpu_device = emscripten_webgpu_get_device();
|
wgpu_device = emscripten_webgpu_get_device();
|
||||||
if (!wgpu_device)
|
if (!wgpu_device)
|
||||||
@ -130,7 +125,7 @@ static bool init_wgpu()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void main_loop(void* window)
|
static void MainLoopStep(void* window)
|
||||||
{
|
{
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
@ -141,13 +136,10 @@ static void main_loop(void* window)
|
|||||||
if (width != wgpu_swap_chain_width && height != wgpu_swap_chain_height)
|
if (width != wgpu_swap_chain_width && height != wgpu_swap_chain_height)
|
||||||
{
|
{
|
||||||
ImGui_ImplWGPU_InvalidateDeviceObjects();
|
ImGui_ImplWGPU_InvalidateDeviceObjects();
|
||||||
|
|
||||||
if (wgpu_swap_chain)
|
if (wgpu_swap_chain)
|
||||||
wgpuSwapChainRelease(wgpu_swap_chain);
|
wgpuSwapChainRelease(wgpu_swap_chain);
|
||||||
|
|
||||||
wgpu_swap_chain_width = width;
|
wgpu_swap_chain_width = width;
|
||||||
wgpu_swap_chain_height = height;
|
wgpu_swap_chain_height = height;
|
||||||
|
|
||||||
WGPUSwapChainDescriptor swap_chain_desc = {};
|
WGPUSwapChainDescriptor swap_chain_desc = {};
|
||||||
swap_chain_desc.usage = WGPUTextureUsage_RenderAttachment;
|
swap_chain_desc.usage = WGPUTextureUsage_RenderAttachment;
|
||||||
swap_chain_desc.format = WGPUTextureFormat_RGBA8Unorm;
|
swap_chain_desc.format = WGPUTextureFormat_RGBA8Unorm;
|
||||||
@ -155,7 +147,6 @@ static void main_loop(void* window)
|
|||||||
swap_chain_desc.height = height;
|
swap_chain_desc.height = height;
|
||||||
swap_chain_desc.presentMode = WGPUPresentMode_Fifo;
|
swap_chain_desc.presentMode = WGPUPresentMode_Fifo;
|
||||||
wgpu_swap_chain = wgpuDeviceCreateSwapChain(wgpu_device, wgpu_surface, &swap_chain_desc);
|
wgpu_swap_chain = wgpuDeviceCreateSwapChain(wgpu_device, wgpu_surface, &swap_chain_desc);
|
||||||
|
|
||||||
ImGui_ImplWGPU_CreateDeviceObjects();
|
ImGui_ImplWGPU_CreateDeviceObjects();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +155,12 @@ static void main_loop(void* window)
|
|||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -229,7 +226,7 @@ static void main_loop(void* window)
|
|||||||
|
|
||||||
static void print_glfw_error(int error, const char* description)
|
static void print_glfw_error(int error, const char* description)
|
||||||
{
|
{
|
||||||
printf("Glfw Error %d: %s\n", error, description);
|
printf("GLFW Error %d: %s\n", error, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_wgpu_error(WGPUErrorType error_type, const char* message, void*)
|
static void print_wgpu_error(WGPUErrorType error_type, const char* message, void*)
|
||||||
|
@ -23,22 +23,30 @@
|
|||||||
#pragma comment(lib, "legacy_stdio_definitions")
|
#pragma comment(lib, "legacy_stdio_definitions")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Data
|
||||||
|
static GLFWwindow* g_AppWindow = NULL;
|
||||||
|
|
||||||
|
// Forward declarations of helper functions
|
||||||
|
void MainLoopStep();
|
||||||
static void glfw_error_callback(int error, const char* description)
|
static void glfw_error_callback(int error, const char* description)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
|
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main code
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Setup window
|
|
||||||
glfwSetErrorCallback(glfw_error_callback);
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
// Create window with graphics context
|
||||||
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL2 example", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL2 example", NULL, NULL);
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1); // Enable vsync
|
glfwSwapInterval(1); // Enable vsync
|
||||||
|
g_AppWindow = window;
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
// Setup Dear ImGui context
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
@ -83,19 +91,29 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
|
MainLoopStep();
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplOpenGL2_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
glfwDestroyWindow(window);
|
||||||
|
glfwTerminate();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainLoopStep()
|
||||||
{
|
{
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
// Poll and handle events (inputs, window resize, etc.)
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
GLFWwindow* window = g_AppWindow;
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
@ -103,6 +121,12 @@ int main(int, char**)
|
|||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -159,7 +183,7 @@ int main(int, char**)
|
|||||||
// Update and Render additional Platform Windows
|
// Update and Render additional Platform Windows
|
||||||
// (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
|
// (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
|
||||||
// For this specific demo app we could also call glfwMakeContextCurrent(window) directly)
|
// For this specific demo app we could also call glfwMakeContextCurrent(window) directly)
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
GLFWwindow* backup_current_context = glfwGetCurrentContext();
|
GLFWwindow* backup_current_context = glfwGetCurrentContext();
|
||||||
ImGui::UpdatePlatformWindows();
|
ImGui::UpdatePlatformWindows();
|
||||||
@ -167,16 +191,6 @@ int main(int, char**)
|
|||||||
glfwMakeContextCurrent(backup_current_context);
|
glfwMakeContextCurrent(backup_current_context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
ImGui_ImplOpenGL2_Shutdown();
|
|
||||||
ImGui_ImplGlfw_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
glfwDestroyWindow(window);
|
|
||||||
glfwTerminate();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# This Makefile assumes you have loaded emscripten's environment.
|
# This Makefile assumes you have loaded emscripten's environment.
|
||||||
# (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
|
# (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
|
||||||
#
|
#
|
||||||
# Running `make` will produce three files:
|
# Running `make -f Makefile.emscripten` will produce three files:
|
||||||
# - web/index.html
|
# - web/index.html
|
||||||
# - web/index.js
|
# - web/index.js
|
||||||
# - web/index.wasm
|
# - web/index.wasm
|
||||||
@ -32,9 +32,8 @@ EMS =
|
|||||||
##---------------------------------------------------------------------
|
##---------------------------------------------------------------------
|
||||||
|
|
||||||
# ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
|
# ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only)
|
||||||
EMS += -s USE_GLFW=3
|
|
||||||
EMS += -s DISABLE_EXCEPTION_CATCHING=1
|
EMS += -s DISABLE_EXCEPTION_CATCHING=1
|
||||||
LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
|
LDFLAGS += -s USE_GLFW=3 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1
|
||||||
|
|
||||||
# Uncomment next line to fix possible rendering bugs with Emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877)
|
# Uncomment next line to fix possible rendering bugs with Emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877)
|
||||||
#EMS += -s BINARYEN_TRAP_MODE=clamp
|
#EMS += -s BINARYEN_TRAP_MODE=clamp
|
||||||
@ -60,7 +59,8 @@ endif
|
|||||||
CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
|
CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
|
||||||
#CPPFLAGS += -g
|
#CPPFLAGS += -g
|
||||||
CPPFLAGS += -Wall -Wformat -Os $(EMS)
|
CPPFLAGS += -Wall -Wformat -Os $(EMS)
|
||||||
LDFLAGS += --shell-file shell_minimal.html $(EMS)
|
# LDFLAGS += --shell-file ../libs/emscripten/shell_minimal.html
|
||||||
|
LDFLAGS += $(EMS)
|
||||||
|
|
||||||
##---------------------------------------------------------------------
|
##---------------------------------------------------------------------
|
||||||
## BUILD RULES
|
## BUILD RULES
|
@ -3,6 +3,8 @@
|
|||||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||||
|
|
||||||
|
// This example can also compile and run with Emscripten. See Makefile.emscripten for details.
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_impl_glfw.h"
|
#include "imgui_impl_glfw.h"
|
||||||
#include "imgui_impl_opengl3.h"
|
#include "imgui_impl_opengl3.h"
|
||||||
@ -20,14 +22,24 @@
|
|||||||
#pragma comment(lib, "legacy_stdio_definitions")
|
#pragma comment(lib, "legacy_stdio_definitions")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Data
|
||||||
|
static GLFWwindow* g_AppWindow = NULL;
|
||||||
|
|
||||||
|
// Forward declarations of helper functions
|
||||||
|
void MainLoopStep();
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#include <emscripten.h>
|
||||||
|
void MainLoopForEmscripten(void*) { MainLoopStep(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
static void glfw_error_callback(int error, const char* description)
|
static void glfw_error_callback(int error, const char* description)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
|
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main code
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Setup window
|
|
||||||
glfwSetErrorCallback(glfw_error_callback);
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
return 1;
|
return 1;
|
||||||
@ -61,6 +73,7 @@ int main(int, char**)
|
|||||||
return 1;
|
return 1;
|
||||||
glfwMakeContextCurrent(window);
|
glfwMakeContextCurrent(window);
|
||||||
glfwSwapInterval(1); // Enable vsync
|
glfwSwapInterval(1); // Enable vsync
|
||||||
|
g_AppWindow = window;
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
// Setup Dear ImGui context
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
@ -97,6 +110,7 @@ int main(int, char**)
|
|||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details.
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
|
// - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See Makefile.emscripten for details.
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefault();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||||
@ -105,19 +119,36 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
|
#ifndef __EMSCRIPTEN__
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
|
MainLoopStep();
|
||||||
|
#else
|
||||||
|
// For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file.
|
||||||
|
// You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
|
||||||
|
io.IniFilename = NULL;
|
||||||
|
emscripten_set_main_loop_arg(MainLoopForEmscripten, NULL, 0, true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
glfwDestroyWindow(window);
|
||||||
|
glfwTerminate();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainLoopStep()
|
||||||
{
|
{
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
// Poll and handle events (inputs, window resize, etc.)
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
GLFWwindow* window = g_AppWindow;
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
@ -125,6 +156,12 @@ int main(int, char**)
|
|||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -174,7 +211,7 @@ int main(int, char**)
|
|||||||
// Update and Render additional Platform Windows
|
// Update and Render additional Platform Windows
|
||||||
// (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
|
// (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
|
||||||
// For this specific demo app we could also call glfwMakeContextCurrent(window) directly)
|
// For this specific demo app we could also call glfwMakeContextCurrent(window) directly)
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
GLFWwindow* backup_current_context = glfwGetCurrentContext();
|
GLFWwindow* backup_current_context = glfwGetCurrentContext();
|
||||||
ImGui::UpdatePlatformWindows();
|
ImGui::UpdatePlatformWindows();
|
||||||
@ -184,14 +221,3 @@ int main(int, char**)
|
|||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
|
||||||
ImGui_ImplGlfw_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
glfwDestroyWindow(window);
|
|
||||||
glfwTerminate();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
#define IMGUI_VULKAN_DEBUG_REPORT
|
#define IMGUI_VULKAN_DEBUG_REPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Data
|
||||||
static VkAllocationCallbacks* g_Allocator = NULL;
|
static VkAllocationCallbacks* g_Allocator = NULL;
|
||||||
static VkInstance g_Instance = VK_NULL_HANDLE;
|
static VkInstance g_Instance = VK_NULL_HANDLE;
|
||||||
static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
|
static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
|
||||||
@ -41,10 +42,17 @@ static VkDebugReportCallbackEXT g_DebugReport = VK_NULL_HANDLE;
|
|||||||
static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
|
static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
|
||||||
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
|
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
|
||||||
|
|
||||||
|
static GLFWwindow* g_AppWindow = NULL;
|
||||||
static ImGui_ImplVulkanH_Window g_MainWindowData;
|
static ImGui_ImplVulkanH_Window g_MainWindowData;
|
||||||
static int g_MinImageCount = 2;
|
static int g_MinImageCount = 2;
|
||||||
static bool g_SwapChainRebuild = false;
|
static bool g_SwapChainRebuild = false;
|
||||||
|
|
||||||
|
// Forward declarations of helper functions
|
||||||
|
void MainLoopStep();
|
||||||
|
static void glfw_error_callback(int error, const char* description)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
|
||||||
|
}
|
||||||
static void check_vk_result(VkResult err)
|
static void check_vk_result(VkResult err)
|
||||||
{
|
{
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
@ -347,22 +355,16 @@ static void FramePresent(ImGui_ImplVulkanH_Window* wd)
|
|||||||
wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->ImageCount; // Now we can use the next set of semaphores
|
wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->ImageCount; // Now we can use the next set of semaphores
|
||||||
}
|
}
|
||||||
|
|
||||||
static void glfw_error_callback(int error, const char* description)
|
// Main code
|
||||||
{
|
|
||||||
fprintf(stderr, "Glfw Error %d: %s\n", error, description);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Setup GLFW window
|
|
||||||
glfwSetErrorCallback(glfw_error_callback);
|
glfwSetErrorCallback(glfw_error_callback);
|
||||||
if (!glfwInit())
|
if (!glfwInit())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
// Create window with Vulkan context
|
||||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+Vulkan example", NULL, NULL);
|
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+Vulkan example", NULL, NULL);
|
||||||
|
|
||||||
// Setup Vulkan
|
|
||||||
if (!glfwVulkanSupported())
|
if (!glfwVulkanSupported())
|
||||||
{
|
{
|
||||||
printf("GLFW: Vulkan Not Supported\n");
|
printf("GLFW: Vulkan Not Supported\n");
|
||||||
@ -371,6 +373,7 @@ int main(int, char**)
|
|||||||
uint32_t extensions_count = 0;
|
uint32_t extensions_count = 0;
|
||||||
const char** extensions = glfwGetRequiredInstanceExtensions(&extensions_count);
|
const char** extensions = glfwGetRequiredInstanceExtensions(&extensions_count);
|
||||||
SetupVulkan(extensions, extensions_count);
|
SetupVulkan(extensions, extensions_count);
|
||||||
|
g_AppWindow = window;
|
||||||
|
|
||||||
// Create Window Surface
|
// Create Window Surface
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
@ -470,19 +473,34 @@ int main(int, char**)
|
|||||||
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
|
MainLoopStep();
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
err = vkDeviceWaitIdle(g_Device);
|
||||||
|
check_vk_result(err);
|
||||||
|
ImGui_ImplVulkan_Shutdown();
|
||||||
|
ImGui_ImplGlfw_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
CleanupVulkanWindow();
|
||||||
|
CleanupVulkan();
|
||||||
|
|
||||||
|
glfwDestroyWindow(window);
|
||||||
|
glfwTerminate();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainLoopStep()
|
||||||
{
|
{
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
// Poll and handle events (inputs, window resize, etc.)
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
GLFWwindow* window = g_AppWindow;
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
// Resize swap chain?
|
// Resize swap chain?
|
||||||
@ -504,6 +522,12 @@ int main(int, char**)
|
|||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -545,6 +569,7 @@ int main(int, char**)
|
|||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
ImDrawData* main_draw_data = ImGui::GetDrawData();
|
ImDrawData* main_draw_data = ImGui::GetDrawData();
|
||||||
const bool main_is_minimized = (main_draw_data->DisplaySize.x <= 0.0f || main_draw_data->DisplaySize.y <= 0.0f);
|
const bool main_is_minimized = (main_draw_data->DisplaySize.x <= 0.0f || main_draw_data->DisplaySize.y <= 0.0f);
|
||||||
|
ImGui_ImplVulkanH_Window* wd = &g_MainWindowData;
|
||||||
wd->ClearValue.color.float32[0] = clear_color.x * clear_color.w;
|
wd->ClearValue.color.float32[0] = clear_color.x * clear_color.w;
|
||||||
wd->ClearValue.color.float32[1] = clear_color.y * clear_color.w;
|
wd->ClearValue.color.float32[1] = clear_color.y * clear_color.w;
|
||||||
wd->ClearValue.color.float32[2] = clear_color.z * clear_color.w;
|
wd->ClearValue.color.float32[2] = clear_color.z * clear_color.w;
|
||||||
@ -553,7 +578,7 @@ int main(int, char**)
|
|||||||
FrameRender(wd, main_draw_data);
|
FrameRender(wd, main_draw_data);
|
||||||
|
|
||||||
// Update and Render additional Platform Windows
|
// Update and Render additional Platform Windows
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
ImGui::UpdatePlatformWindows();
|
ImGui::UpdatePlatformWindows();
|
||||||
ImGui::RenderPlatformWindowsDefault();
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
@ -563,19 +588,3 @@ int main(int, char**)
|
|||||||
if (!main_is_minimized)
|
if (!main_is_minimized)
|
||||||
FramePresent(wd);
|
FramePresent(wd);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
err = vkDeviceWaitIdle(g_Device);
|
|
||||||
check_vk_result(err);
|
|
||||||
ImGui_ImplVulkan_Shutdown();
|
|
||||||
ImGui_ImplGlfw_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
CleanupVulkanWindow();
|
|
||||||
CleanupVulkan();
|
|
||||||
|
|
||||||
glfwDestroyWindow(window);
|
|
||||||
glfwTerminate();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
@ -28,13 +28,86 @@
|
|||||||
#pragma warning (disable: 4505) // unreferenced local function has been removed
|
#pragma warning (disable: 4505) // unreferenced local function has been removed
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Forward declarations of helper functions
|
||||||
|
void MainLoopStep();
|
||||||
|
|
||||||
// Our state
|
// Our state
|
||||||
static bool show_demo_window = true;
|
static bool show_demo_window = true;
|
||||||
static bool show_another_window = false;
|
static bool show_another_window = false;
|
||||||
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
|
|
||||||
void my_display_code()
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
|
// Create GLUT window
|
||||||
|
glutInit(&argc, argv);
|
||||||
|
#ifdef __FREEGLUT_EXT_H__
|
||||||
|
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
|
||||||
|
#endif
|
||||||
|
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_MULTISAMPLE);
|
||||||
|
glutInitWindowSize(1280, 720);
|
||||||
|
glutCreateWindow("Dear ImGui GLUT+OpenGL2 Example");
|
||||||
|
|
||||||
|
// Setup GLUT display function
|
||||||
|
// We will also call ImGui_ImplGLUT_InstallFuncs() to get all the other functions installed for us,
|
||||||
|
// otherwise it is possible to install our own functions and call the imgui_impl_glut.h functions ourselves.
|
||||||
|
glutDisplayFunc(MainLoopStep);
|
||||||
|
|
||||||
|
// Setup Dear ImGui context
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||||
|
//io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
||||||
|
|
||||||
|
// Setup Dear ImGui style
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
//ImGui::StyleColorsLight();
|
||||||
|
|
||||||
|
// Setup Platform/Renderer backends
|
||||||
|
// FIXME: Consider reworking this example to install our own GLUT funcs + forward calls ImGui_ImplGLUT_XXX ones, instead of using ImGui_ImplGLUT_InstallFuncs().
|
||||||
|
ImGui_ImplGLUT_Init();
|
||||||
|
ImGui_ImplOpenGL2_Init();
|
||||||
|
|
||||||
|
// Install GLUT handlers (glutReshapeFunc(), glutMotionFunc(), glutPassiveMotionFunc(), glutMouseFunc(), glutKeyboardFunc() etc.)
|
||||||
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
ImGui_ImplGLUT_InstallFuncs();
|
||||||
|
|
||||||
|
// Load Fonts
|
||||||
|
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
||||||
|
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
||||||
|
// - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
||||||
|
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
||||||
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
|
//io.Fonts->AddFontDefault();
|
||||||
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
||||||
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
|
//IM_ASSERT(font != NULL);
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
glutMainLoop();
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplOpenGL2_Shutdown();
|
||||||
|
ImGui_ImplGLUT_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainLoopStep()
|
||||||
|
{
|
||||||
|
// Start the Dear ImGui frame
|
||||||
|
ImGui_ImplOpenGL2_NewFrame();
|
||||||
|
ImGui_ImplGLUT_NewFrame();
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -71,15 +144,6 @@ void my_display_code()
|
|||||||
show_another_window = false;
|
show_another_window = false;
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void glut_display_func()
|
|
||||||
{
|
|
||||||
// Start the Dear ImGui frame
|
|
||||||
ImGui_ImplOpenGL2_NewFrame();
|
|
||||||
ImGui_ImplGLUT_NewFrame();
|
|
||||||
|
|
||||||
my_display_code();
|
|
||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
@ -93,67 +157,3 @@ void glut_display_func()
|
|||||||
glutSwapBuffers();
|
glutSwapBuffers();
|
||||||
glutPostRedisplay();
|
glutPostRedisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
|
||||||
{
|
|
||||||
// Create GLUT window
|
|
||||||
glutInit(&argc, argv);
|
|
||||||
#ifdef __FREEGLUT_EXT_H__
|
|
||||||
glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS);
|
|
||||||
#endif
|
|
||||||
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_MULTISAMPLE);
|
|
||||||
glutInitWindowSize(1280, 720);
|
|
||||||
glutCreateWindow("Dear ImGui GLUT+OpenGL2 Example");
|
|
||||||
|
|
||||||
// Setup GLUT display function
|
|
||||||
// We will also call ImGui_ImplGLUT_InstallFuncs() to get all the other functions installed for us,
|
|
||||||
// otherwise it is possible to install our own functions and call the imgui_impl_glut.h functions ourselves.
|
|
||||||
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
|
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
|
||||||
|
|
||||||
// Setup Dear ImGui style
|
|
||||||
ImGui::StyleColorsDark();
|
|
||||||
//ImGui::StyleColorsLight();
|
|
||||||
|
|
||||||
// Setup Platform/Renderer backends
|
|
||||||
// FIXME: Consider reworking this example to install our own GLUT funcs + forward calls ImGui_ImplGLUT_XXX ones, instead of using ImGui_ImplGLUT_InstallFuncs().
|
|
||||||
ImGui_ImplGLUT_Init();
|
|
||||||
ImGui_ImplGLUT_InstallFuncs();
|
|
||||||
ImGui_ImplOpenGL2_Init();
|
|
||||||
|
|
||||||
// Load Fonts
|
|
||||||
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
|
|
||||||
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
|
||||||
// - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
|
|
||||||
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
|
||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details.
|
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
|
||||||
//io.Fonts->AddFontDefault();
|
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
|
||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
|
||||||
//IM_ASSERT(font != NULL);
|
|
||||||
|
|
||||||
glutMainLoop();
|
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
ImGui_ImplOpenGL2_Shutdown();
|
|
||||||
ImGui_ImplGLUT_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
@ -12,12 +12,14 @@
|
|||||||
#include <SDL_syswm.h>
|
#include <SDL_syswm.h>
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
|
static SDL_Window* g_AppWindow = NULL;
|
||||||
static ID3D11Device* g_pd3dDevice = NULL;
|
static ID3D11Device* g_pd3dDevice = NULL;
|
||||||
static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
|
static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
|
||||||
static IDXGISwapChain* g_pSwapChain = NULL;
|
static IDXGISwapChain* g_pSwapChain = NULL;
|
||||||
static ID3D11RenderTargetView* g_mainRenderTargetView = NULL;
|
static ID3D11RenderTargetView* g_mainRenderTargetView = NULL;
|
||||||
|
|
||||||
// Forward declarations of helper functions
|
// Forward declarations of helper functions
|
||||||
|
bool MainLoopStep();
|
||||||
bool CreateDeviceD3D(HWND hWnd);
|
bool CreateDeviceD3D(HWND hWnd);
|
||||||
void CleanupDeviceD3D();
|
void CleanupDeviceD3D();
|
||||||
void CreateRenderTarget();
|
void CreateRenderTarget();
|
||||||
@ -42,6 +44,7 @@ int main(int, char**)
|
|||||||
SDL_VERSION(&wmInfo.version);
|
SDL_VERSION(&wmInfo.version);
|
||||||
SDL_GetWindowWMInfo(window, &wmInfo);
|
SDL_GetWindowWMInfo(window, &wmInfo);
|
||||||
HWND hwnd = (HWND)wmInfo.info.win.window;
|
HWND hwnd = (HWND)wmInfo.info.win.window;
|
||||||
|
g_AppWindow = window;
|
||||||
|
|
||||||
// Initialize Direct3D
|
// Initialize Direct3D
|
||||||
if (!CreateDeviceD3D(hwnd))
|
if (!CreateDeviceD3D(hwnd))
|
||||||
@ -93,28 +96,41 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool done = false;
|
while (true)
|
||||||
while (!done)
|
|
||||||
{
|
{
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
if (!MainLoopStep())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplDX11_Shutdown();
|
||||||
|
ImGui_ImplSDL2_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
CleanupDeviceD3D();
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainLoopStep()
|
||||||
|
{
|
||||||
|
// Poll and handle SDL events (inputs, window resize, etc.)
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
SDL_Window* window = g_AppWindow;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
done = true;
|
return false;
|
||||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
||||||
done = true;
|
return false;
|
||||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED && event.window.windowID == SDL_GetWindowID(window))
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED && event.window.windowID == SDL_GetWindowID(window))
|
||||||
{
|
{
|
||||||
// Release all outstanding references to the swap chain's buffers before resizing.
|
// Release all outstanding references to the swap chain's buffers before resizing.
|
||||||
@ -129,6 +145,12 @@ int main(int, char**)
|
|||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -174,7 +196,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
// Update and Render additional Platform Windows
|
// Update and Render additional Platform Windows
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
ImGui::UpdatePlatformWindows();
|
ImGui::UpdatePlatformWindows();
|
||||||
ImGui::RenderPlatformWindowsDefault();
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
@ -182,22 +204,11 @@ int main(int, char**)
|
|||||||
|
|
||||||
g_pSwapChain->Present(1, 0); // Present with vsync
|
g_pSwapChain->Present(1, 0); // Present with vsync
|
||||||
//g_pSwapChain->Present(0, 0); // Present without vsync
|
//g_pSwapChain->Present(0, 0); // Present without vsync
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup
|
// Helper functions to use DirectX11
|
||||||
ImGui_ImplDX11_Shutdown();
|
|
||||||
ImGui_ImplSDL2_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
CleanupDeviceD3D();
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
SDL_Quit();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper functions
|
|
||||||
|
|
||||||
bool CreateDeviceD3D(HWND hWnd)
|
bool CreateDeviceD3D(HWND hWnd)
|
||||||
{
|
{
|
||||||
// Setup swap chain
|
// Setup swap chain
|
||||||
|
@ -14,12 +14,16 @@
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <SDL_opengl.h>
|
#include <SDL_opengl.h>
|
||||||
|
|
||||||
|
// Data
|
||||||
|
static SDL_Window* g_AppWindow = NULL;
|
||||||
|
|
||||||
|
// Forward declarations of helper functions
|
||||||
|
bool MainLoopStep();
|
||||||
|
|
||||||
// Main code
|
// Main code
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Setup SDL
|
// Setup SDL
|
||||||
// (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems,
|
|
||||||
// depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to the latest version of SDL is recommended!)
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
@ -37,6 +41,7 @@ int main(int, char**)
|
|||||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||||
SDL_GL_MakeCurrent(window, gl_context);
|
SDL_GL_MakeCurrent(window, gl_context);
|
||||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||||
|
g_AppWindow = window;
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
// Setup Dear ImGui context
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
@ -81,35 +86,55 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool done = false;
|
while (true)
|
||||||
while (!done)
|
|
||||||
{
|
{
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
if (!MainLoopStep())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplOpenGL2_Shutdown();
|
||||||
|
ImGui_ImplSDL2_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
SDL_GL_DeleteContext(gl_context);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainLoopStep()
|
||||||
|
{
|
||||||
|
// Poll and handle SDL events (inputs, window resize, etc.)
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
SDL_Window* window = g_AppWindow;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
done = true;
|
return false;
|
||||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
||||||
done = true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
ImGui_ImplOpenGL2_NewFrame();
|
ImGui_ImplOpenGL2_NewFrame();
|
||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -168,16 +193,6 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
}
|
|
||||||
|
return true;
|
||||||
// Cleanup
|
|
||||||
ImGui_ImplOpenGL2_Shutdown();
|
|
||||||
ImGui_ImplSDL2_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
SDL_GL_DeleteContext(gl_context);
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
SDL_Quit();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
# This Makefile assumes you have loaded emscripten's environment.
|
# This Makefile assumes you have loaded emscripten's environment.
|
||||||
# (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
|
# (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead)
|
||||||
#
|
#
|
||||||
# Running `make` will produce three files:
|
# Running `make -f Makefile.emscripten` will produce three files:
|
||||||
# - web/index.html
|
# - web/index.html
|
||||||
# - web/index.js
|
# - web/index.js
|
||||||
# - web/index.wasm
|
# - web/index.wasm
|
||||||
@ -60,7 +60,8 @@ endif
|
|||||||
CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
|
CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
|
||||||
#CPPFLAGS += -g
|
#CPPFLAGS += -g
|
||||||
CPPFLAGS += -Wall -Wformat -Os $(EMS)
|
CPPFLAGS += -Wall -Wformat -Os $(EMS)
|
||||||
LDFLAGS += --shell-file shell_minimal.html $(EMS)
|
LDFLAGS += --shell-file ../libs/emscripten/shell_minimal.html
|
||||||
|
LDFLAGS += $(EMS)
|
||||||
|
|
||||||
##---------------------------------------------------------------------
|
##---------------------------------------------------------------------
|
||||||
## BUILD RULES
|
## BUILD RULES
|
@ -1,12 +1,13 @@
|
|||||||
|
|
||||||
# How to Build
|
# How to Build
|
||||||
|
|
||||||
- On Windows with Visual Studio's IDE
|
## Windows with Visual Studio's IDE
|
||||||
|
|
||||||
Use the provided project file (.vcxproj). Add to solution (imgui_examples.sln) if necessary.
|
Use the provided project file (.vcxproj). Add to solution (imgui_examples.sln) if necessary.
|
||||||
|
|
||||||
- On Windows with Visual Studio's CLI
|
## Windows with Visual Studio's CLI
|
||||||
|
|
||||||
|
Use build_win32.bat or directly:
|
||||||
```
|
```
|
||||||
set SDL2_DIR=path_to_your_sdl2_folder
|
set SDL2_DIR=path_to_your_sdl2_folder
|
||||||
cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console
|
cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x86 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console
|
||||||
@ -15,15 +16,42 @@ cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_
|
|||||||
cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x64 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console
|
cl /Zi /MD /I.. /I..\.. /I%SDL2_DIR%\include main.cpp ..\..\backends\imgui_impl_sdl.cpp ..\..\backends\imgui_impl_opengl3.cpp ..\..\imgui*.cpp /FeDebug/example_sdl_opengl3.exe /FoDebug/ /link /libpath:%SDL2_DIR%\lib\x64 SDL2.lib SDL2main.lib opengl32.lib /subsystem:console
|
||||||
```
|
```
|
||||||
|
|
||||||
- On Linux and similar Unixes
|
## Linux and similar Unixes
|
||||||
|
|
||||||
|
Use our Makefile or directly:
|
||||||
```
|
```
|
||||||
c++ `sdl2-config --cflags` -I .. -I ../.. -I ../../backends main.cpp ../../backends/imgui_impl_sdl.cpp ../../backends/imgui_impl_opengl3.cpp ../../imgui*.cpp `sdl2-config --libs` -lGL -ldl
|
c++ `sdl2-config --cflags` -I .. -I ../.. -I ../../backends
|
||||||
|
main.cpp ../../backends/imgui_impl_sdl.cpp ../../backends/imgui_impl_opengl3.cpp ../../imgui*.cpp
|
||||||
|
`sdl2-config --libs` -lGL -ldl
|
||||||
```
|
```
|
||||||
|
|
||||||
- On Mac OS X
|
## macOS
|
||||||
|
|
||||||
|
Use our Makefile or directly:
|
||||||
```
|
```
|
||||||
brew install sdl2
|
brew install sdl2
|
||||||
c++ `sdl2-config --cflags` -I .. -I ../.. -I ../../backends main.cpp ../../backends/imgui_impl_sdl.cpp ../../backends/imgui_impl_opengl3.cpp ../../imgui*.cpp `sdl2-config --libs` -framework OpenGl -framework CoreFoundation
|
c++ `sdl2-config --cflags` -I .. -I ../.. -I ../../backends
|
||||||
|
main.cpp ../../backends/imgui_impl_sdl.cpp ../../backends/imgui_impl_opengl3.cpp ../../imgui*.cpp
|
||||||
|
`sdl2-config --libs` -framework OpenGl -framework CoreFoundation
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Emscripten
|
||||||
|
|
||||||
|
**Building**
|
||||||
|
|
||||||
|
You need to install Emscripten from https://emscripten.org/docs/getting_started/downloads.html, and have the environment variables set, as described in https://emscripten.org/docs/getting_started/downloads.html#installation-instructions
|
||||||
|
|
||||||
|
- Depending on your configuration, in Windows you may need to run `emsdk/emsdk_env.bat` in your console to access the Emscripten command-line tools.
|
||||||
|
- You may also refer to our [Continuous Integration setup](https://github.com/ocornut/imgui/tree/master/.github/workflows) for Emscripten setup.
|
||||||
|
- Then build using `make -f Makefile.emscripten` while in the current directory.
|
||||||
|
|
||||||
|
**Running an Emscripten project**
|
||||||
|
|
||||||
|
To run on a local machine:
|
||||||
|
- `make -f Makefile.emscripten serve` will use Python3 to spawn a local webserver, you can then browse http://localhost:8000 to access your build.
|
||||||
|
- Otherwise, generally you will need a local webserver. Quoting [https://emscripten.org/docs/getting_started](https://emscripten.org/docs/getting_started/Tutorial.html#generating-html):<br>
|
||||||
|
_"Unfortunately several browsers (including Chrome, Safari, and Internet Explorer) do not support file:// [XHR](https://emscripten.org/docs/site/glossary.html#term-xhr) requests, and can’t load extra files needed by the HTML (like a .wasm file, or packaged file data as mentioned lower down). For these browsers you’ll need to serve the files using a [local webserver](https://emscripten.org/docs/getting_started/FAQ.html#faq-local-webserver) and then open http://localhost:8000/hello.html."_
|
||||||
|
- Emscripten SDK has a handy `emrun` command: `emrun web/index.html --browser firefox` which will spawn a temporary local webserver (in Firefox). See https://emscripten.org/docs/compiling/Running-html-files-with-emrun.html for details.
|
||||||
|
- You may use Python 3 builtin webserver: `python -m http.server -d web` (this is what `make serve` uses).
|
||||||
|
- You may use Python 2 builtin webserver: `cd web && python -m SimpleHTTPServer`.
|
||||||
|
- If you are accessing the files over a network, certain browsers, such as Firefox, will restrict Gamepad API access to secure contexts only (e.g. https only).
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
// If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp.
|
||||||
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
// Read online: https://github.com/ocornut/imgui/tree/master/docs
|
||||||
|
|
||||||
|
// This example can also compile and run with Emscripten. See Makefile.emscripten for details.
|
||||||
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_impl_sdl.h"
|
#include "imgui_impl_sdl.h"
|
||||||
#include "imgui_impl_opengl3.h"
|
#include "imgui_impl_opengl3.h"
|
||||||
@ -14,12 +16,20 @@
|
|||||||
#include <SDL_opengl.h>
|
#include <SDL_opengl.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Data
|
||||||
|
static SDL_Window* g_AppWindow = NULL;
|
||||||
|
|
||||||
|
// Forward declarations of helper functions
|
||||||
|
bool MainLoopStep();
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#include <emscripten.h>
|
||||||
|
void MainLoopForEmscripten(void*) { MainLoopStep(); }
|
||||||
|
#endif
|
||||||
|
|
||||||
// Main code
|
// Main code
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Setup SDL
|
// Setup SDL
|
||||||
// (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems,
|
|
||||||
// depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to the latest version of SDL is recommended!)
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
@ -59,6 +69,7 @@ int main(int, char**)
|
|||||||
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||||
SDL_GL_MakeCurrent(window, gl_context);
|
SDL_GL_MakeCurrent(window, gl_context);
|
||||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||||
|
g_AppWindow = window;
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
// Setup Dear ImGui context
|
||||||
IMGUI_CHECKVERSION();
|
IMGUI_CHECKVERSION();
|
||||||
@ -95,6 +106,7 @@ int main(int, char**)
|
|||||||
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
||||||
// - Read 'docs/FONTS.md' for more instructions and details.
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
|
// - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See Makefile.emscripten for details.
|
||||||
//io.Fonts->AddFontDefault();
|
//io.Fonts->AddFontDefault();
|
||||||
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
//io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
||||||
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
//io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||||
@ -103,35 +115,64 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool done = false;
|
#ifndef __EMSCRIPTEN__
|
||||||
while (!done)
|
// Desktop Build
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
if (!MainLoopStep())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
// Emscripten Build
|
||||||
|
// For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file.
|
||||||
|
// You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
|
||||||
|
io.IniFilename = NULL;
|
||||||
|
emscripten_set_main_loop_arg(MainLoopForEmscripten, NULL, 0, true);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplSDL2_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
SDL_GL_DeleteContext(gl_context);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainLoopStep()
|
||||||
|
{
|
||||||
|
// Poll and handle SDL events (inputs, window resize, etc.)
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
SDL_Window* window = g_AppWindow;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
done = true;
|
return false;
|
||||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
||||||
done = true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -179,7 +220,7 @@ int main(int, char**)
|
|||||||
// Update and Render additional Platform Windows
|
// Update and Render additional Platform Windows
|
||||||
// (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
|
// (Platform functions may change the current OpenGL context, so we save/restore it to make it easier to paste this code elsewhere.
|
||||||
// For this specific demo app we could also call SDL_GL_MakeCurrent(window, gl_context) directly)
|
// For this specific demo app we could also call SDL_GL_MakeCurrent(window, gl_context) directly)
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
|
SDL_Window* backup_current_window = SDL_GL_GetCurrentWindow();
|
||||||
SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
|
SDL_GLContext backup_current_context = SDL_GL_GetCurrentContext();
|
||||||
@ -189,16 +230,6 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_SwapWindow(window);
|
SDL_GL_SwapWindow(window);
|
||||||
}
|
|
||||||
|
return true;
|
||||||
// Cleanup
|
|
||||||
ImGui_ImplOpenGL3_Shutdown();
|
|
||||||
ImGui_ImplSDL2_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
SDL_GL_DeleteContext(gl_context);
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
SDL_Quit();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -17,29 +17,34 @@
|
|||||||
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
|
#error This backend requires SDL 2.0.17+ because of SDL_RenderGeometry() function
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Data
|
||||||
|
static SDL_Window* g_AppWindow = NULL;
|
||||||
|
static SDL_Renderer* g_AppWindowRenderer = NULL;
|
||||||
|
|
||||||
|
// Forward declarations of helper functions
|
||||||
|
bool MainLoopStep();
|
||||||
|
|
||||||
// Main code
|
// Main code
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Setup SDL
|
// Setup SDL
|
||||||
// (Some versions of SDL before <2.0.10 appears to have performance/stalling issues on a minority of Windows systems,
|
|
||||||
// depending on whether SDL_INIT_GAMECONTROLLER is enabled or disabled.. updating to the latest version of SDL is recommended!)
|
|
||||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
|
||||||
{
|
{
|
||||||
printf("Error: %s\n", SDL_GetError());
|
printf("Error: %s\n", SDL_GetError());
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup window
|
// Create window with SDL_Renderer graphics context
|
||||||
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+SDL_Renderer example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
|
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+SDL_Renderer example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
|
||||||
|
|
||||||
// Setup SDL_Renderer instance
|
|
||||||
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED);
|
||||||
if (renderer == NULL)
|
if (renderer == NULL)
|
||||||
{
|
{
|
||||||
SDL_Log("Error creating SDL_Renderer!");
|
SDL_Log("Error creating SDL_Renderer!");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
g_AppWindow = window;
|
||||||
|
g_AppWindowRenderer = renderer;
|
||||||
//SDL_RendererInfo info;
|
//SDL_RendererInfo info;
|
||||||
//SDL_GetRendererInfo(renderer, &info);
|
//SDL_GetRendererInfo(renderer, &info);
|
||||||
//SDL_Log("Current SDL_Renderer: %s", info.name);
|
//SDL_Log("Current SDL_Renderer: %s", info.name);
|
||||||
@ -75,35 +80,56 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool done = false;
|
while (true)
|
||||||
while (!done)
|
{
|
||||||
|
if (!MainLoopStep())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplSDLRenderer_Shutdown();
|
||||||
|
ImGui_ImplSDL2_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
SDL_DestroyRenderer(renderer);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainLoopStep()
|
||||||
{
|
{
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
// Poll and handle events (inputs, window resize, etc.)
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
SDL_Window* window = g_AppWindow;
|
||||||
|
SDL_Renderer* renderer = g_AppWindowRenderer;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
done = true;
|
return false;
|
||||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
||||||
done = true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
ImGui_ImplSDLRenderer_NewFrame();
|
ImGui_ImplSDLRenderer_NewFrame();
|
||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -148,16 +174,6 @@ int main(int, char**)
|
|||||||
SDL_RenderClear(renderer);
|
SDL_RenderClear(renderer);
|
||||||
ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplSDLRenderer_RenderDrawData(ImGui::GetDrawData());
|
||||||
SDL_RenderPresent(renderer);
|
SDL_RenderPresent(renderer);
|
||||||
}
|
|
||||||
|
return true;
|
||||||
// Cleanup
|
|
||||||
ImGui_ImplSDLRenderer_Shutdown();
|
|
||||||
ImGui_ImplSDL2_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
SDL_DestroyRenderer(renderer);
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
SDL_Quit();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
<Filter>imgui</Filter>
|
<Filter>imgui</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="..\..\imgui_tables.cpp">
|
<ClCompile Include="..\..\imgui_tables.cpp">
|
||||||
<Filter>sources</Filter>
|
<Filter>imgui</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#define IMGUI_VULKAN_DEBUG_REPORT
|
#define IMGUI_VULKAN_DEBUG_REPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Data
|
||||||
static VkAllocationCallbacks* g_Allocator = NULL;
|
static VkAllocationCallbacks* g_Allocator = NULL;
|
||||||
static VkInstance g_Instance = VK_NULL_HANDLE;
|
static VkInstance g_Instance = VK_NULL_HANDLE;
|
||||||
static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
|
static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
|
||||||
@ -33,10 +34,14 @@ static VkDebugReportCallbackEXT g_DebugReport = VK_NULL_HANDLE;
|
|||||||
static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
|
static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
|
||||||
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
|
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
|
||||||
|
|
||||||
|
static SDL_Window* g_AppWindow = NULL;
|
||||||
static ImGui_ImplVulkanH_Window g_MainWindowData;
|
static ImGui_ImplVulkanH_Window g_MainWindowData;
|
||||||
static uint32_t g_MinImageCount = 2;
|
static uint32_t g_MinImageCount = 2;
|
||||||
static bool g_SwapChainRebuild = false;
|
static bool g_SwapChainRebuild = false;
|
||||||
|
|
||||||
|
// Forward declarations of helper functions
|
||||||
|
bool MainLoopStep();
|
||||||
|
|
||||||
static void check_vk_result(VkResult err)
|
static void check_vk_result(VkResult err)
|
||||||
{
|
{
|
||||||
if (err == 0)
|
if (err == 0)
|
||||||
@ -339,6 +344,7 @@ static void FramePresent(ImGui_ImplVulkanH_Window* wd)
|
|||||||
wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->ImageCount; // Now we can use the next set of semaphores
|
wd->SemaphoreIndex = (wd->SemaphoreIndex + 1) % wd->ImageCount; // Now we can use the next set of semaphores
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main code
|
||||||
int main(int, char**)
|
int main(int, char**)
|
||||||
{
|
{
|
||||||
// Setup SDL
|
// Setup SDL
|
||||||
@ -348,17 +354,16 @@ int main(int, char**)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup window
|
// Create window with Vulkan graphics context
|
||||||
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_VULKAN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+Vulkan example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
|
SDL_Window* window = SDL_CreateWindow("Dear ImGui SDL2+Vulkan example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
|
||||||
|
|
||||||
// Setup Vulkan
|
|
||||||
uint32_t extensions_count = 0;
|
uint32_t extensions_count = 0;
|
||||||
SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, NULL);
|
SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, NULL);
|
||||||
const char** extensions = new const char*[extensions_count];
|
const char** extensions = new const char*[extensions_count];
|
||||||
SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, extensions);
|
SDL_Vulkan_GetInstanceExtensions(window, &extensions_count, extensions);
|
||||||
SetupVulkan(extensions, extensions_count);
|
SetupVulkan(extensions, extensions_count);
|
||||||
delete[] extensions;
|
delete[] extensions;
|
||||||
|
g_AppWindow = window;
|
||||||
|
|
||||||
// Create Window Surface
|
// Create Window Surface
|
||||||
VkSurfaceKHR surface;
|
VkSurfaceKHR surface;
|
||||||
@ -462,28 +467,45 @@ int main(int, char**)
|
|||||||
ImGui_ImplVulkan_DestroyFontUploadObjects();
|
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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool done = false;
|
while (true)
|
||||||
while (!done)
|
{
|
||||||
|
if (!MainLoopStep())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
err = vkDeviceWaitIdle(g_Device);
|
||||||
|
check_vk_result(err);
|
||||||
|
ImGui_ImplVulkan_Shutdown();
|
||||||
|
ImGui_ImplSDL2_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
CleanupVulkanWindow();
|
||||||
|
CleanupVulkan();
|
||||||
|
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainLoopStep()
|
||||||
{
|
{
|
||||||
// Poll and handle events (inputs, window resize, etc.)
|
// Poll and handle events (inputs, window resize, etc.)
|
||||||
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data.
|
||||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data.
|
||||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||||
|
SDL_Window* window = g_AppWindow;
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while (SDL_PollEvent(&event))
|
while (SDL_PollEvent(&event))
|
||||||
{
|
{
|
||||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||||
if (event.type == SDL_QUIT)
|
if (event.type == SDL_QUIT)
|
||||||
done = true;
|
return false;
|
||||||
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
|
||||||
done = true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resize swap chain?
|
// Resize swap chain?
|
||||||
@ -505,6 +527,12 @@ int main(int, char**)
|
|||||||
ImGui_ImplSDL2_NewFrame();
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -546,6 +574,7 @@ int main(int, char**)
|
|||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
ImDrawData* main_draw_data = ImGui::GetDrawData();
|
ImDrawData* main_draw_data = ImGui::GetDrawData();
|
||||||
const bool main_is_minimized = (main_draw_data->DisplaySize.x <= 0.0f || main_draw_data->DisplaySize.y <= 0.0f);
|
const bool main_is_minimized = (main_draw_data->DisplaySize.x <= 0.0f || main_draw_data->DisplaySize.y <= 0.0f);
|
||||||
|
ImGui_ImplVulkanH_Window* wd = &g_MainWindowData;
|
||||||
wd->ClearValue.color.float32[0] = clear_color.x * clear_color.w;
|
wd->ClearValue.color.float32[0] = clear_color.x * clear_color.w;
|
||||||
wd->ClearValue.color.float32[1] = clear_color.y * clear_color.w;
|
wd->ClearValue.color.float32[1] = clear_color.y * clear_color.w;
|
||||||
wd->ClearValue.color.float32[2] = clear_color.z * clear_color.w;
|
wd->ClearValue.color.float32[2] = clear_color.z * clear_color.w;
|
||||||
@ -554,7 +583,7 @@ int main(int, char**)
|
|||||||
FrameRender(wd, main_draw_data);
|
FrameRender(wd, main_draw_data);
|
||||||
|
|
||||||
// Update and Render additional Platform Windows
|
// Update and Render additional Platform Windows
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
ImGui::UpdatePlatformWindows();
|
ImGui::UpdatePlatformWindows();
|
||||||
ImGui::RenderPlatformWindowsDefault();
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
@ -563,20 +592,6 @@ int main(int, char**)
|
|||||||
// Present Main Platform Window
|
// Present Main Platform Window
|
||||||
if (!main_is_minimized)
|
if (!main_is_minimized)
|
||||||
FramePresent(wd);
|
FramePresent(wd);
|
||||||
}
|
|
||||||
|
return true;
|
||||||
// Cleanup
|
|
||||||
err = vkDeviceWaitIdle(g_Device);
|
|
||||||
check_vk_result(err);
|
|
||||||
ImGui_ImplVulkan_Shutdown();
|
|
||||||
ImGui_ImplSDL2_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
CleanupVulkanWindow();
|
|
||||||
CleanupVulkan();
|
|
||||||
|
|
||||||
SDL_DestroyWindow(window);
|
|
||||||
SDL_Quit();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ static IDXGISwapChain* g_pSwapChain = NULL;
|
|||||||
static ID3D10RenderTargetView* g_mainRenderTargetView = NULL;
|
static ID3D10RenderTargetView* g_mainRenderTargetView = NULL;
|
||||||
|
|
||||||
// Forward declarations of helper functions
|
// Forward declarations of helper functions
|
||||||
|
bool MainLoopStep();
|
||||||
bool CreateDeviceD3D(HWND hWnd);
|
bool CreateDeviceD3D(HWND hWnd);
|
||||||
void CleanupDeviceD3D();
|
void CleanupDeviceD3D();
|
||||||
void CreateRenderTarget();
|
void CreateRenderTarget();
|
||||||
@ -85,17 +86,30 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool done = false;
|
while (true)
|
||||||
while (!done)
|
{
|
||||||
|
if (!MainLoopStep())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplDX10_Shutdown();
|
||||||
|
ImGui_ImplWin32_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
CleanupDeviceD3D();
|
||||||
|
::DestroyWindow(hwnd);
|
||||||
|
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainLoopStep()
|
||||||
{
|
{
|
||||||
// Poll and handle messages (inputs, window resize, etc.)
|
// Poll and handle messages (inputs, window resize, etc.)
|
||||||
// See the WndProc() function below for our to dispatch events to the Win32 backend.
|
// See the WndProc() function below where we dispatch events to the imgui_impl_win32 backend.
|
||||||
|
bool done = false;
|
||||||
MSG msg;
|
MSG msg;
|
||||||
while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
||||||
{
|
{
|
||||||
@ -105,13 +119,19 @@ int main(int, char**)
|
|||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
if (done)
|
if (done)
|
||||||
break;
|
return false;
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
ImGui_ImplDX10_NewFrame();
|
ImGui_ImplDX10_NewFrame();
|
||||||
ImGui_ImplWin32_NewFrame();
|
ImGui_ImplWin32_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -157,7 +177,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplDX10_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplDX10_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
// Update and Render additional Platform Windows
|
// Update and Render additional Platform Windows
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
ImGui::UpdatePlatformWindows();
|
ImGui::UpdatePlatformWindows();
|
||||||
ImGui::RenderPlatformWindowsDefault();
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
@ -165,17 +185,8 @@ int main(int, char**)
|
|||||||
|
|
||||||
g_pSwapChain->Present(1, 0); // Present with vsync
|
g_pSwapChain->Present(1, 0); // Present with vsync
|
||||||
//g_pSwapChain->Present(0, 0); // Present without vsync
|
//g_pSwapChain->Present(0, 0); // Present without vsync
|
||||||
}
|
|
||||||
|
|
||||||
ImGui_ImplDX10_Shutdown();
|
return true;
|
||||||
ImGui_ImplWin32_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
CleanupDeviceD3D();
|
|
||||||
::DestroyWindow(hwnd);
|
|
||||||
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
@ -15,6 +15,7 @@ static IDXGISwapChain* g_pSwapChain = NULL;
|
|||||||
static ID3D11RenderTargetView* g_mainRenderTargetView = NULL;
|
static ID3D11RenderTargetView* g_mainRenderTargetView = NULL;
|
||||||
|
|
||||||
// Forward declarations of helper functions
|
// Forward declarations of helper functions
|
||||||
|
bool MainLoopStep();
|
||||||
bool CreateDeviceD3D(HWND hWnd);
|
bool CreateDeviceD3D(HWND hWnd);
|
||||||
void CleanupDeviceD3D();
|
void CleanupDeviceD3D();
|
||||||
void CreateRenderTarget();
|
void CreateRenderTarget();
|
||||||
@ -90,17 +91,30 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool done = false;
|
while (true)
|
||||||
while (!done)
|
{
|
||||||
|
if (!MainLoopStep())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplDX11_Shutdown();
|
||||||
|
ImGui_ImplWin32_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
CleanupDeviceD3D();
|
||||||
|
::DestroyWindow(hwnd);
|
||||||
|
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainLoopStep()
|
||||||
{
|
{
|
||||||
// Poll and handle messages (inputs, window resize, etc.)
|
// Poll and handle messages (inputs, window resize, etc.)
|
||||||
// See the WndProc() function below for our to dispatch events to the Win32 backend.
|
// See the WndProc() function below where we dispatch events to the imgui_impl_win32 backend.
|
||||||
|
bool done = false;
|
||||||
MSG msg;
|
MSG msg;
|
||||||
while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
||||||
{
|
{
|
||||||
@ -110,13 +124,19 @@ int main(int, char**)
|
|||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
if (done)
|
if (done)
|
||||||
break;
|
return false;
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
ImGui_ImplDX11_NewFrame();
|
ImGui_ImplDX11_NewFrame();
|
||||||
ImGui_ImplWin32_NewFrame();
|
ImGui_ImplWin32_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -162,7 +182,7 @@ int main(int, char**)
|
|||||||
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
|
||||||
// Update and Render additional Platform Windows
|
// Update and Render additional Platform Windows
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
ImGui::UpdatePlatformWindows();
|
ImGui::UpdatePlatformWindows();
|
||||||
ImGui::RenderPlatformWindowsDefault();
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
@ -170,18 +190,7 @@ int main(int, char**)
|
|||||||
|
|
||||||
g_pSwapChain->Present(1, 0); // Present with vsync
|
g_pSwapChain->Present(1, 0); // Present with vsync
|
||||||
//g_pSwapChain->Present(0, 0); // Present without vsync
|
//g_pSwapChain->Present(0, 0); // Present without vsync
|
||||||
}
|
return true;
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
ImGui_ImplDX11_Shutdown();
|
|
||||||
ImGui_ImplWin32_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
CleanupDeviceD3D();
|
|
||||||
::DestroyWindow(hwnd);
|
|
||||||
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
@ -48,6 +48,7 @@ static ID3D12Resource* g_mainRenderTargetResource[NUM_BACK_BUFFERS]
|
|||||||
static D3D12_CPU_DESCRIPTOR_HANDLE g_mainRenderTargetDescriptor[NUM_BACK_BUFFERS] = {};
|
static D3D12_CPU_DESCRIPTOR_HANDLE g_mainRenderTargetDescriptor[NUM_BACK_BUFFERS] = {};
|
||||||
|
|
||||||
// Forward declarations of helper functions
|
// Forward declarations of helper functions
|
||||||
|
bool MainLoopStep();
|
||||||
bool CreateDeviceD3D(HWND hWnd);
|
bool CreateDeviceD3D(HWND hWnd);
|
||||||
void CleanupDeviceD3D();
|
void CleanupDeviceD3D();
|
||||||
void CreateRenderTarget();
|
void CreateRenderTarget();
|
||||||
@ -123,17 +124,31 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool done = false;
|
while (true)
|
||||||
while (!done)
|
{
|
||||||
|
if (!MainLoopStep())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
WaitForLastSubmittedFrame();
|
||||||
|
ImGui_ImplDX12_Shutdown();
|
||||||
|
ImGui_ImplWin32_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
CleanupDeviceD3D();
|
||||||
|
::DestroyWindow(hwnd);
|
||||||
|
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainLoopStep()
|
||||||
{
|
{
|
||||||
// Poll and handle messages (inputs, window resize, etc.)
|
// Poll and handle messages (inputs, window resize, etc.)
|
||||||
// See the WndProc() function below for our to dispatch events to the Win32 backend.
|
// See the WndProc() function below where we dispatch events to the imgui_impl_win32 backend.
|
||||||
|
bool done = false;
|
||||||
MSG msg;
|
MSG msg;
|
||||||
while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
||||||
{
|
{
|
||||||
@ -143,13 +158,19 @@ int main(int, char**)
|
|||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
if (done)
|
if (done)
|
||||||
break;
|
return false;
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
ImGui_ImplDX12_NewFrame();
|
ImGui_ImplDX12_NewFrame();
|
||||||
ImGui_ImplWin32_NewFrame();
|
ImGui_ImplWin32_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -218,7 +239,7 @@ int main(int, char**)
|
|||||||
g_pd3dCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&g_pd3dCommandList);
|
g_pd3dCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&g_pd3dCommandList);
|
||||||
|
|
||||||
// Update and Render additional Platform Windows
|
// Update and Render additional Platform Windows
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
ImGui::UpdatePlatformWindows();
|
ImGui::UpdatePlatformWindows();
|
||||||
ImGui::RenderPlatformWindowsDefault(NULL, (void*)g_pd3dCommandList);
|
ImGui::RenderPlatformWindowsDefault(NULL, (void*)g_pd3dCommandList);
|
||||||
@ -231,20 +252,8 @@ int main(int, char**)
|
|||||||
g_pd3dCommandQueue->Signal(g_fence, fenceValue);
|
g_pd3dCommandQueue->Signal(g_fence, fenceValue);
|
||||||
g_fenceLastSignaledValue = fenceValue;
|
g_fenceLastSignaledValue = fenceValue;
|
||||||
frameCtx->FenceValue = fenceValue;
|
frameCtx->FenceValue = fenceValue;
|
||||||
}
|
|
||||||
|
|
||||||
WaitForLastSubmittedFrame();
|
return true;
|
||||||
|
|
||||||
// Cleanup
|
|
||||||
ImGui_ImplDX12_Shutdown();
|
|
||||||
ImGui_ImplWin32_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
CleanupDeviceD3D();
|
|
||||||
::DestroyWindow(hwnd);
|
|
||||||
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
@ -14,6 +14,7 @@ static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
|
|||||||
static D3DPRESENT_PARAMETERS g_d3dpp = {};
|
static D3DPRESENT_PARAMETERS g_d3dpp = {};
|
||||||
|
|
||||||
// Forward declarations of helper functions
|
// Forward declarations of helper functions
|
||||||
|
bool MainLoopStep();
|
||||||
bool CreateDeviceD3D(HWND hWnd);
|
bool CreateDeviceD3D(HWND hWnd);
|
||||||
void CleanupDeviceD3D();
|
void CleanupDeviceD3D();
|
||||||
void ResetDevice();
|
void ResetDevice();
|
||||||
@ -83,17 +84,30 @@ int main(int, char**)
|
|||||||
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
//ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
|
||||||
//IM_ASSERT(font != NULL);
|
//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);
|
|
||||||
|
|
||||||
// Main loop
|
// Main loop
|
||||||
bool done = false;
|
while (true)
|
||||||
while (!done)
|
{
|
||||||
|
if (!MainLoopStep())
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplDX9_Shutdown();
|
||||||
|
ImGui_ImplWin32_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
CleanupDeviceD3D();
|
||||||
|
::DestroyWindow(hwnd);
|
||||||
|
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainLoopStep()
|
||||||
{
|
{
|
||||||
// Poll and handle messages (inputs, window resize, etc.)
|
// Poll and handle messages (inputs, window resize, etc.)
|
||||||
// See the WndProc() function below for our to dispatch events to the Win32 backend.
|
// See the WndProc() function below where we dispatch events to the imgui_impl_win32 backend.
|
||||||
|
bool done = false;
|
||||||
MSG msg;
|
MSG msg;
|
||||||
while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
while (::PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
|
||||||
{
|
{
|
||||||
@ -103,13 +117,19 @@ int main(int, char**)
|
|||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
if (done)
|
if (done)
|
||||||
break;
|
return false;
|
||||||
|
|
||||||
// Start the Dear ImGui frame
|
// Start the Dear ImGui frame
|
||||||
ImGui_ImplDX9_NewFrame();
|
ImGui_ImplDX9_NewFrame();
|
||||||
ImGui_ImplWin32_NewFrame();
|
ImGui_ImplWin32_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
// (we use static, which essentially makes the variable globals, as a convenience to keep the example code easy to follow)
|
||||||
|
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);
|
||||||
|
|
||||||
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
if (show_demo_window)
|
if (show_demo_window)
|
||||||
ImGui::ShowDemoWindow(&show_demo_window);
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
@ -162,7 +182,7 @@ int main(int, char**)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update and Render additional Platform Windows
|
// Update and Render additional Platform Windows
|
||||||
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
|
||||||
{
|
{
|
||||||
ImGui::UpdatePlatformWindows();
|
ImGui::UpdatePlatformWindows();
|
||||||
ImGui::RenderPlatformWindowsDefault();
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
@ -173,17 +193,8 @@ int main(int, char**)
|
|||||||
// Handle loss of D3D9 device
|
// Handle loss of D3D9 device
|
||||||
if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
|
if (result == D3DERR_DEVICELOST && g_pd3dDevice->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
|
||||||
ResetDevice();
|
ResetDevice();
|
||||||
}
|
|
||||||
|
|
||||||
ImGui_ImplDX9_Shutdown();
|
return true;
|
||||||
ImGui_ImplWin32_Shutdown();
|
|
||||||
ImGui::DestroyContext();
|
|
||||||
|
|
||||||
CleanupDeviceD3D();
|
|
||||||
::DestroyWindow(hwnd);
|
|
||||||
::UnregisterClassW(wc.lpszClassName, wc.hInstance);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
@ -3,9 +3,10 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no"/>
|
||||||
<title>Dear ImGui SDL+Emscripten example</title>
|
<title>Dear ImGui Emscripten example</title>
|
||||||
<style>
|
<style>
|
||||||
body { margin: 0; background-color: black }
|
body { margin: 0; background-color: black }
|
||||||
|
/* FIXME: with our GLFW example this block seems to break resizing and io.DisplaySize gets stuck */
|
||||||
.emscripten {
|
.emscripten {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0px;
|
top: 0px;
|
@ -6068,6 +6068,9 @@ void ImGui::ShowAboutWindow(bool* p_open)
|
|||||||
#ifdef __clang_version__
|
#ifdef __clang_version__
|
||||||
ImGui::Text("define: __clang_version__=%s", __clang_version__);
|
ImGui::Text("define: __clang_version__=%s", __clang_version__);
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
ImGui::Text("define: __EMSCRIPTEN__");
|
||||||
|
#endif
|
||||||
#ifdef IMGUI_HAS_VIEWPORT
|
#ifdef IMGUI_HAS_VIEWPORT
|
||||||
ImGui::Text("define: IMGUI_HAS_VIEWPORT");
|
ImGui::Text("define: IMGUI_HAS_VIEWPORT");
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user