mirror of
https://github.com/ocornut/imgui.git
synced 2024-11-12 02:00:58 +01:00
Examples: Emscripten+GLFW: revert to use a shell_minimal.html closer to vanilla one, as our fullscreen + misc tweaks to Emscripten+SDL example to match other version.
This commit is contained in:
parent
0370856d78
commit
b51919dce1
1
.gitignore
vendored
1
.gitignore
vendored
@ -40,6 +40,7 @@ xcuserdata
|
|||||||
examples/*.o.tmp
|
examples/*.o.tmp
|
||||||
examples/*.out.js
|
examples/*.out.js
|
||||||
examples/*.out.wasm
|
examples/*.out.wasm
|
||||||
|
examples/example_emscripten_glfw_opengl3/web/*
|
||||||
examples/example_emscripten_opengl3/web/*
|
examples/example_emscripten_opengl3/web/*
|
||||||
examples/example_emscripten_wgpu/web/*
|
examples/example_emscripten_wgpu/web/*
|
||||||
|
|
||||||
|
@ -32,9 +32,9 @@ 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 +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 shell_minimal.html
|
||||||
|
LDFLAGS += $(EMS)
|
||||||
|
|
||||||
##---------------------------------------------------------------------
|
##---------------------------------------------------------------------
|
||||||
## BUILD RULES
|
## BUILD RULES
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<title>Dear ImGui GLFW+Emscripten example</title>
|
<title>Dear ImGui GLFW+Emscripten example</title>
|
||||||
<style>
|
<style>
|
||||||
body { margin: 0; background-color: black }
|
body { margin: 0; background-color: black }
|
||||||
.emscripten {
|
/*.emscripten {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 0px;
|
top: 0px;
|
||||||
left: 0px;
|
left: 0px;
|
||||||
@ -24,7 +24,8 @@
|
|||||||
image-rendering: crisp-edges;
|
image-rendering: crisp-edges;
|
||||||
image-rendering: pixelated;
|
image-rendering: pixelated;
|
||||||
-ms-interpolation-mode: nearest-neighbor;
|
-ms-interpolation-mode: nearest-neighbor;
|
||||||
}
|
}*/
|
||||||
|
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -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 shell_minimal.html
|
||||||
|
LDFLAGS += $(EMS)
|
||||||
|
|
||||||
##---------------------------------------------------------------------
|
##---------------------------------------------------------------------
|
||||||
## BUILD RULES
|
## BUILD RULES
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
// Emscripten requires to have full control over the main loop. We're going to store our SDL book-keeping variables globally.
|
// 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.
|
// 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_Window* g_Window = NULL;
|
||||||
SDL_GLContext g_GLContext = NULL;
|
|
||||||
|
|
||||||
// For clarity, our main loop code is declared at the end.
|
// For clarity, our main loop code is declared at the end.
|
||||||
static void main_loop(void*);
|
static void main_loop(void*);
|
||||||
@ -49,13 +48,14 @@ int main(int, char**)
|
|||||||
SDL_DisplayMode current;
|
SDL_DisplayMode current;
|
||||||
SDL_GetCurrentDisplayMode(0, ¤t);
|
SDL_GetCurrentDisplayMode(0, ¤t);
|
||||||
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
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);
|
SDL_Window* 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);
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||||
if (!g_GLContext)
|
if (!gl_context)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Failed to initialize WebGL context!\n");
|
fprintf(stderr, "Failed to initialize GL context!\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
SDL_GL_MakeCurrent(window, gl_context);
|
||||||
SDL_GL_SetSwapInterval(1); // Enable vsync
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||||
|
|
||||||
// Setup Dear ImGui context
|
// Setup Dear ImGui context
|
||||||
@ -74,7 +74,7 @@ int main(int, char**)
|
|||||||
//ImGui::StyleColorsLight();
|
//ImGui::StyleColorsLight();
|
||||||
|
|
||||||
// Setup Platform/Renderer backends
|
// Setup Platform/Renderer backends
|
||||||
ImGui_ImplSDL2_InitForOpenGL(g_Window, g_GLContext);
|
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
|
||||||
ImGui_ImplOpenGL3_Init(glsl_version);
|
ImGui_ImplOpenGL3_Init(glsl_version);
|
||||||
|
|
||||||
// Load Fonts
|
// Load Fonts
|
||||||
@ -98,6 +98,7 @@ int main(int, char**)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// This function call won't return, and will engage in an infinite loop, processing events from the browser, and dispatching them.
|
// This function call won't return, and will engage in an infinite loop, processing events from the browser, and dispatching them.
|
||||||
|
g_Window = window;
|
||||||
emscripten_set_main_loop_arg(main_loop, NULL, 0, true);
|
emscripten_set_main_loop_arg(main_loop, NULL, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,16 +138,16 @@ static void main_loop(void* arg)
|
|||||||
static float f = 0.0f;
|
static float f = 0.0f;
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
|
|
||||||
ImGui::Begin("Hello, world!"); // Create a window called "Hello, world!" and append into it.
|
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::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("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
||||||
ImGui::Checkbox("Another Window", &show_another_window);
|
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::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
|
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)
|
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
||||||
counter++;
|
counter++;
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Text("counter = %d", counter);
|
ImGui::Text("counter = %d", counter);
|
||||||
@ -158,7 +159,7 @@ static void main_loop(void* arg)
|
|||||||
// 3. Show another simple window.
|
// 3. Show another simple window.
|
||||||
if (show_another_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::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!");
|
ImGui::Text("Hello from another window!");
|
||||||
if (ImGui::Button("Close Me"))
|
if (ImGui::Button("Close Me"))
|
||||||
show_another_window = false;
|
show_another_window = false;
|
||||||
@ -167,7 +168,6 @@ static void main_loop(void* arg)
|
|||||||
|
|
||||||
// Rendering
|
// Rendering
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
SDL_GL_MakeCurrent(g_Window, g_GLContext);
|
|
||||||
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
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);
|
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);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
Loading…
Reference in New Issue
Block a user