Enable font loading for wasm builds.
PiperOrigin-RevId: 842627994 Change-Id: I347f79ec668f31a8bbc4d26638a045e29084d715
This commit is contained in:
committed by
Copybara-Service
parent
f06aa45ea6
commit
9c1b8d8cfb
@@ -41,7 +41,7 @@ extern void* GetNativeWindowOsx(void* window);
|
|||||||
namespace mujoco::platform {
|
namespace mujoco::platform {
|
||||||
|
|
||||||
static void InitImGui(SDL_Window* window, const LoadAssetFn& load_asset_fn,
|
static void InitImGui(SDL_Window* window, const LoadAssetFn& load_asset_fn,
|
||||||
bool build_fonts) {
|
bool load_fonts, bool build_fonts) {
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
@@ -51,25 +51,24 @@ static void InitImGui(SDL_Window* window, const LoadAssetFn& load_asset_fn,
|
|||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
ImGui_ImplSDL2_InitForOther(window);
|
ImGui_ImplSDL2_InitForOther(window);
|
||||||
|
|
||||||
#ifndef __EMSCRIPTEN__
|
if (load_fonts) {
|
||||||
// TODO: Get font loading working for wasm.
|
// Note: fonts are stored statically because they aren't actually loaded
|
||||||
// Note: fonts are stored statically because they aren't actually loaded
|
// until the fonts are built.
|
||||||
// until the fonts are built.
|
ImFontConfig main_cfg;
|
||||||
ImFontConfig main_cfg;
|
static auto main_font = load_asset_fn("OpenSans-Regular.ttf");
|
||||||
static auto main_font = load_asset_fn("OpenSans-Regular.ttf");
|
io.Fonts->AddFontFromMemoryTTF(main_font.data(), main_font.size(), 20.f,
|
||||||
io.Fonts->AddFontFromMemoryTTF(main_font.data(), main_font.size(), 20.f,
|
&main_cfg);
|
||||||
&main_cfg);
|
|
||||||
|
|
||||||
ImFontConfig icon_cfg;
|
ImFontConfig icon_cfg;
|
||||||
icon_cfg.MergeMode = true;
|
icon_cfg.MergeMode = true;
|
||||||
static auto icon_font = load_asset_fn("fontawesome-webfont.ttf");
|
static auto icon_font = load_asset_fn("fontawesome-webfont.ttf");
|
||||||
constexpr ImWchar icon_ranges[] = {0xf000, 0xf3ff, 0x000};
|
constexpr ImWchar icon_ranges[] = {0xf000, 0xf3ff, 0x000};
|
||||||
io.Fonts->AddFontFromMemoryTTF(icon_font.data(), icon_font.size(), 14.f,
|
io.Fonts->AddFontFromMemoryTTF(icon_font.data(), icon_font.size(), 14.f,
|
||||||
&icon_cfg, icon_ranges);
|
&icon_cfg, icon_ranges);
|
||||||
#endif
|
|
||||||
|
|
||||||
if (build_fonts) {
|
if (build_fonts) {
|
||||||
io.Fonts->Build();
|
io.Fonts->Build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +113,8 @@ Window::Window(std::string_view title, int width, int height, Config config,
|
|||||||
mju_error("Error creating window: %s", SDL_GetError());
|
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) {
|
if (render_config == kFilamentWebGL || render_config == kClassicOpenGL) {
|
||||||
SDL_GLContext gl_context = SDL_GL_CreateContext(sdl_window_);
|
SDL_GLContext gl_context = SDL_GL_CreateContext(sdl_window_);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ class Window {
|
|||||||
struct Config {
|
struct Config {
|
||||||
RenderConfig render_config = kClassicOpenGL;
|
RenderConfig render_config = kClassicOpenGL;
|
||||||
bool enable_keyboard = true;
|
bool enable_keyboard = true;
|
||||||
|
bool load_fonts = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
Window(std::string_view title, int width, int height, Config config,
|
Window(std::string_view title, int width, int height, Config config,
|
||||||
|
|||||||
Reference in New Issue
Block a user