Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable 4k/retina support (example_emscripten_wgpu) #7151

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/example_emscripten_wgpu/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
CC = emcc
CXX = em++
WEB_DIR = web
EXE = $(WEB_DIR)/index.js
EXE = $(WEB_DIR)/index.html
IMGUI_DIR = ../..
SOURCES = main.cpp
SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp
Expand Down Expand Up @@ -56,7 +56,7 @@ endif
CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends
#CPPFLAGS += -g
CPPFLAGS += -Wall -Wformat -Os $(EMS)
#LDFLAGS += --shell-file shell_minimal.html
LDFLAGS += --shell-file ../libs/emscripten/shell_minimal.html
LDFLAGS += $(EMS)

##---------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion examples/example_emscripten_wgpu/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ int main(int, char**)
// Make sure GLFW does not initialize any graphics context.
// This needs to be done explicitly later.
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
// Enable 4k/retina support (since emscripten 3.1.51)
glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+WebGPU example", nullptr, nullptr);
if (!window)
{
Expand Down Expand Up @@ -76,7 +78,7 @@ int main(int, char**)

// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOther(window, true);
ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas");
ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas-container");
ImGui_ImplWGPU_Init(wgpu_device, 3, wgpu_preferred_fmt, WGPUTextureFormat_Undefined);

// Load Fonts
Expand Down
80 changes: 0 additions & 80 deletions examples/example_emscripten_wgpu/web/index.html

This file was deleted.

6 changes: 5 additions & 1 deletion examples/example_glfw_opengl3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ int main(int, char**)
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
//glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only
#endif
#ifdef __EMSCRIPTEN__
// Enable 4k/retina support (since emscripten 3.1.51)
glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_TRUE);
#endif

// Create window with graphics context
GLFWwindow* window = glfwCreateWindow(1280, 720, "Dear ImGui GLFW+OpenGL3 example", nullptr, nullptr);
Expand All @@ -85,7 +89,7 @@ int main(int, char**)
// Setup Platform/Renderer backends
ImGui_ImplGlfw_InitForOpenGL(window, true);
#ifdef __EMSCRIPTEN__
ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas");
ImGui_ImplGlfw_InstallEmscriptenCanvasResizeCallback("#canvas-container");
#endif
ImGui_ImplOpenGL3_Init(glsl_version);

Expand Down
58 changes: 38 additions & 20 deletions examples/libs/emscripten/shell_minimal.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<title>Dear ImGui Emscripten example</title>
<style>
body { margin: 0; background-color: black }
/* FIXME: with our GLFW example this block seems to break resizing and io.DisplaySize gets stuck */
.emscripten {
position: absolute;
top: 0px;
Expand All @@ -26,39 +25,58 @@
image-rendering: pixelated;
-ms-interpolation-mode: nearest-neighbor;
}
/* prevent ugly blue border in the event the canvas get focus */
#canvas:focus {
outline: none;
}
</style>
</head>
<body>
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<div class="emscripten" id="canvas-container">
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
</div>
<script type='text/javascript'>
var Module = {
preRun: [],
postRun: [],
print: (function() {
var Module;
(async () => {
Module = {
preRun: [],
postRun: [],
print: (function() {
return function(text) {
text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
text = Array.prototype.slice.call(arguments).join(' ');
console.log(text);
};
})(),
printErr: function(text) {
})(),
printErr: function(text) {
text = Array.prototype.slice.call(arguments).join(' ');
console.error(text);
},
canvas: (function() {
},
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) {
})(),
setStatus: function(text) {
console.log("status: " + text);
},
monitorRunDependencies: function(left) {
},
monitorRunDependencies: function(left) {
// no run dependencies to log
}
};
window.onerror = function() {
console.log("onerror: " + event);
};

#if USE_WEBGPU
// Initialize the graphics adapter
{
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
Module.preinitializedWebGPUDevice = device;
}
};
window.onerror = function() {
console.log("onerror: " + event);
};
#endif
})();

</script>
{{{ SCRIPT }}}
</body>
Expand Down