Enable font loading for wasm builds.

PiperOrigin-RevId: 842627994
Change-Id: I347f79ec668f31a8bbc4d26638a045e29084d715
This commit is contained in:
Haroon Qureshi
2025-12-10 02:30:35 -08:00
committed by Copybara-Service
parent f06aa45ea6
commit 9c1b8d8cfb
2 changed files with 20 additions and 19 deletions
+5 -5
View File
@@ -41,7 +41,7 @@ extern void* GetNativeWindowOsx(void* window);
namespace mujoco::platform {
static void InitImGui(SDL_Window* window, const LoadAssetFn& load_asset_fn,
bool build_fonts) {
bool load_fonts, bool build_fonts) {
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
@@ -51,8 +51,7 @@ static void InitImGui(SDL_Window* window, const LoadAssetFn& load_asset_fn,
ImGui::StyleColorsDark();
ImGui_ImplSDL2_InitForOther(window);
#ifndef __EMSCRIPTEN__
// TODO: Get font loading working for wasm.
if (load_fonts) {
// Note: fonts are stored statically because they aren't actually loaded
// until the fonts are built.
ImFontConfig main_cfg;
@@ -66,12 +65,12 @@ static void InitImGui(SDL_Window* window, const LoadAssetFn& load_asset_fn,
constexpr ImWchar icon_ranges[] = {0xf000, 0xf3ff, 0x000};
io.Fonts->AddFontFromMemoryTTF(icon_font.data(), icon_font.size(), 14.f,
&icon_cfg, icon_ranges);
#endif
if (build_fonts) {
io.Fonts->Build();
}
}
}
Window::Window(std::string_view title, int width, int height, Config config,
const LoadAssetFn& load_asset_fn)
@@ -114,7 +113,8 @@ Window::Window(std::string_view title, int width, int height, Config config,
mju_error("Error creating window: %s", SDL_GetError());
}
InitImGui(sdl_window_, load_asset_fn, (render_config != kClassicOpenGL));
InitImGui(sdl_window_, load_asset_fn, config.load_fonts,
(render_config != kClassicOpenGL));
if (render_config == kFilamentWebGL || render_config == kClassicOpenGL) {
SDL_GLContext gl_context = SDL_GL_CreateContext(sdl_window_);
+1
View File
@@ -40,6 +40,7 @@ class Window {
struct Config {
RenderConfig render_config = kClassicOpenGL;
bool enable_keyboard = true;
bool load_fonts = true;
};
Window(std::string_view title, int width, int height, Config config,