Skip to content

Commit

Permalink
Wip / freetype
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Dec 31, 2023
1 parent d0fb180 commit 1ad093d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ option(HELLOIMGUI_ADD_APP_WITH_INSTALL "Add cmake install() instructions with he
# HelloImGui Build options
###############################################################################

#------------------------------------------------------------------------------
################################################################################
# Available backends combinations: HelloImGui needs to use at least one of them.
# If you specify no option:
# - HELLOIMGUI_USE_GLFW_OPENGL3 will be used for Windows, Linux, and macOS
Expand All @@ -54,7 +54,7 @@ option(HELLOIMGUI_ADD_APP_WITH_INSTALL "Add cmake install() instructions with he
# - Only one rendering backend can be used at a time (OpenGL3, Metal or Vulkan)!
# - You may select multiple windowing backends (for example, you may select both SDL and Glfw3)
# - Backends using OpenGL3 as a renderer are easier to use, and are recommended, especially for beginners.
#------------------------------------------------------------------------------
################################################################################
# Standard backends:
# Use Glfw3 + OpenGl3
option(HELLOIMGUI_USE_GLFW_OPENGL3 "Build HelloImGui for Glfw3+OpenGL3" OFF)
Expand All @@ -78,6 +78,11 @@ option(HELLOIMGUI_USE_SDL_DIRECTX11 "Build HelloImGui for SDL2+DirectX11" OFF)
# Experimental! DirectX12 was not tested, although it does compile!
option(HELLOIMGUI_USE_SDL_DIRECTX12 "Build HelloImGui for SDL2+DirectX12" OFF)

#------------------------------------------------------------------------------
# Options / Freetype
#------------------------------------------------------------------------------
option(HELLOIMGUI_USE_FREETYPE "Use freetype for text rendering" OFF)


#------------------------------------------------------------------------------
# Automatic download of Glfw3 and SDL2 (provided as a convenience)
Expand Down
11 changes: 11 additions & 0 deletions hello_imgui_cmake/hello_imgui_build_lib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ function(_him_do_build_imgui)
add_library(imgui ${imgui_sources})
endif()
target_include_directories(imgui PUBLIC ${HELLOIMGUI_IMGUI_SOURCE_DIR})

if (HELLOIMGUI_USE_FREETYPE)
# Note: also change add_imgui.cmake in bundle!
find_package(Freetype REQUIRED)
target_sources(imgui PRIVATE
${HELLOIMGUI_IMGUI_SOURCE_DIR}/misc/freetype/imgui_freetype.cpp
${HELLOIMGUI_IMGUI_SOURCE_DIR}/misc/freetype/imgui_freetype.h)
target_compile_definitions(imgui PUBLIC IMGUI_ENABLE_FREETYPE IMGUI_ENABLE_FREETYPE_LUNASVG)
target_link_libraries(imgui PUBLIC Freetype::Freetype)
endif()

if (MSVC)
hello_imgui_msvc_target_set_folder(imgui ${HELLOIMGUI_SOLUTIONFOLDER}/external)
endif()
Expand Down
5 changes: 5 additions & 0 deletions src/hello_imgui/imgui_default_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "hello_imgui/hello_imgui.h"
#include "hello_imgui/hello_imgui_assets.h"
#include "imgui.h"
#include "misc/freetype/imgui_freetype.h"
#include <string>
#include <map>
#include <stdlib.h>
Expand Down Expand Up @@ -30,6 +31,10 @@ ImFont* LoadFontTTF(const std::string & fontFilename, float fontSize, bool useFu
config.GlyphRanges = glyphRange;
}

// TODO: make this configurable
config.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_LoadColor;


float fontSizeAdjusted = HelloImGui::DpiFontLoadingFactor() * fontSize;
ImFont * font = ImGui::GetIO().Fonts->AddFontFromMemoryTTF(fontData.data, (int)fontData.dataSize, fontSizeAdjusted, &config);
if (font == nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,15 @@ struct AppState
// Additional fonts handling
//////////////////////////////////////////////////////////////////////////
ImFont * gTitleFont;
ImFont * gEmojisFont;
void LoadFonts() // This is called by runnerParams.callbacks.LoadAdditionalFonts
{
// First, load the default font (the default font should be loaded first)
HelloImGui::ImGuiDefaultSettings::LoadDefaultFont_WithFontAwesomeIcons();
// Then load the title font
gTitleFont = HelloImGui::LoadFontTTF("fonts/DroidSans.ttf", 18.f);

gEmojisFont = HelloImGui::LoadFontTTF("fonts/Noto_Color_Emoji/NotoColorEmoji-Regular.ttf", 18.f);
}


Expand Down

0 comments on commit 1ad093d

Please sign in to comment.