Backends: GLFW, Emscripten: fixes for canvas resizing. (#6751)

This commit is contained in:
Pello Rao
2023-12-19 15:52:44 +01:00
committed by ocornut
parent b4c5a83cfe
commit 22a7d241ff
5 changed files with 63 additions and 1 deletions

View File

@ -26,6 +26,8 @@ static WGPUSwapChain wgpu_swap_chain = nullptr;
static int wgpu_swap_chain_width = 0;
static int wgpu_swap_chain_height = 0;
const char* canvas_selector = "#canvas";
// Forward declarations
static void MainLoopStep(void* window);
static bool InitWGPU();
@ -76,6 +78,7 @@ int main(int, char**)
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOther(window, true);
ImGui_ImplGlfw_SetEmscriptenCanvasSelector(canvas_selector);
ImGui_ImplWGPU_Init(wgpu_device, 3, wgpu_preferred_fmt, WGPUTextureFormat_Undefined);
// Load Fonts

View File

@ -59,7 +59,7 @@ endif
CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
#CPPFLAGS += -g
CPPFLAGS += -Wall -Wformat -Os $(EMS)
# LDFLAGS += --shell-file ../libs/emscripten/shell_minimal.html
LDFLAGS += --shell-file ../libs/emscripten/shell_minimal.html
LDFLAGS += $(EMS)
##---------------------------------------------------------------------

View File

@ -26,9 +26,13 @@
// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
#ifdef __EMSCRIPTEN__
#include <emscripten.h>
#include <emscripten/html5.h>
#include "../libs/emscripten/emscripten_mainloop_stub.h"
#endif
const char* canvas_selector = "#canvas";
static void glfw_error_callback(int error, const char* description)
{
fprintf(stderr, "GLFW Error %d: %s\n", error, description);
@ -84,6 +88,9 @@ int main(int, char**)
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window, true);
#ifdef __EMSCRIPTEN__
ImGui_ImplGlfw_SetEmscriptenCanvasSelector(canvas_selector);
#endif
ImGui_ImplOpenGL3_Init(glsl_version);
// Load Fonts