Package imgui
Class ImFontAtlas
java.lang.Object
imgui.binding.ImGuiStruct
imgui.binding.ImGuiStructDestroyable
imgui.ImFontAtlas
Load and rasterize multiple TTF/OTF fonts into a same texture. The font atlas will build a single texture holding:
- One or more fonts.
- Custom graphics data needed to render the shapes needed by Dear ImGui.
- Mouse cursor shapes for software cursor rendering (unless setting 'Flags |= ImFontAtlasFlags_NoMouseCursors' in the font atlas).
It is the user-code responsibility to setup/build the atlas, then upload the pixel data into a texture accessible by your graphics api.
- Optionally, call any of the AddFont*** functions. If you don't call any, the default font embedded in the code will be loaded for you.
- Call GetTexDataAsAlpha8() or GetTexDataAsRGBA32() to build and retrieve pixels data.
- Upload the pixels data into a texture within your graphics system (see imgui_impl_xxxx.cpp examples)
- Call SetTexID(my_tex_id); and pass the pointer/identifier to your texture in a format natural to your graphics API.
This value will be passed back to you during rendering to identify the texture. Read FAQ entry about ImTextureID for more details.
Common pitfalls:
- If you pass a 'glyph_ranges' array to AddFont*** functions, you need to make sure that your array persist up until the
atlas is build (when calling GetTexData*** or Build()). We only copy the pointer, not the data.
- Important: By default, AddFontFromMemoryTTF() takes ownership of the data. Even though we are not writing to it, we will free the pointer on destruction.
You can set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed,
- Even though many functions are suffixed with "TTF", OTF data is supported just as well.
- This is an old API and it is currently awkward for those and and various other reasons! We will address them in the future!
-
Field Summary
Fields inherited from class imgui.binding.ImGuiStruct
ptr -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddCustomRectFontGlyph(ImFont imFont, short id, int width, int height, float advanceX) Id needs to be<0x110000 to register a rectangle to map into a specific font.intaddCustomRectFontGlyph(ImFont imFont, short id, int width, int height, float advanceX, float offsetX, float offsetY) Id needs to be<0x110000 to register a rectangle to map into a specific font.intaddCustomRectFontGlyph(ImFont imFont, short id, int width, int height, float advanceX, ImVec2 offset) Id needs to be<0x110000 to register a rectangle to map into a specific font.intaddCustomRectRegular(int width, int height) voidaddFlags(int flags) Build flags (seeImFontAtlasFlags)addFont(ImFontConfig imFontConfig) addFontDefault(ImFontConfig imFontConfig) Embedded classic pixel-clean bitmap default font — recommended at size 13px with no scaling.addFontDefaultBitmap(ImFontConfig imFontConfig) Embedded classic pixel-clean bitmap default font — recommended at size 13px with no scaling.Embedded scalable (vector) default font — recommended at any higher size.addFontDefaultVector(ImFontConfig imFontConfig) Embedded scalable (vector) default font — recommended at any higher size.addFontFromFileTTF(String filename, float sizePixels) addFontFromFileTTF(String filename, float sizePixels, short[] glyphRanges) addFontFromFileTTF(String filename, float sizePixels, ImFontConfig fontConfig) addFontFromFileTTF(String filename, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges) addFontFromMemoryCompressedBase85TTF(String compressedFontDataBase85, float sizePixels, ImFontConfig fontConfig) 'compressed_font_data_base85' still owned by caller.addFontFromMemoryCompressedBase85TTF(String compressedFontDataBase85, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges) 'compressed_font_data_base85' still owned by caller.addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels) 'compressed_font_data' still owned by caller.addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels, short[] glyphRanges) 'compressed_font_data' still owned by caller.addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels, ImFontConfig imFontConfig) 'compressed_font_data' still owned by caller.addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels, ImFontConfig imFontConfig, short[] glyphRanges) 'compressed_font_data' still owned by caller.addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels) 'compressed_font_data' still owned by caller.addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels, short[] glyphRanges) 'compressed_font_data' still owned by caller.addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels, ImFontConfig imFontConfig) 'compressed_font_data' still owned by caller.addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels, ImFontConfig imFontConfig, short[] glyphRanges) 'compressed_font_data' still owned by caller.addFontFromMemoryTTF(byte[] fontData, float sizePixels) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas.addFontFromMemoryTTF(byte[] fontData, float sizePixels, short[] glyphRanges) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas.addFontFromMemoryTTF(byte[] fontData, float sizePixels, ImFontConfig fontConfig) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas.addFontFromMemoryTTF(byte[] fontData, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas.addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas.addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels, short[] glyphRanges) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas.addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels, ImFontConfig fontConfig) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas.addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas.booleanbuild()Build pixels data.voidclear()Clear all input and output.voidClear output font data (glyphs storage, UV coordinates).voidClear input data (all ImFontConfig structures including sizes, TTF data, glyph ranges, etc.) = all the data used to build the texture and fonts.voidClear output texture data (CPU side).protected longcreate()intgetFlags()Build flags (seeImFontAtlasFlags)short[]Default + Half-Width + Japanese Hiragana/Katakana + full set of about 21000 CJK Unified Ideographsshort[]Default + Half-Width + Japanese Hiragana/Katakana + set of 2500 CJK Unified Ideographs for common simplified Chineseshort[]Default + about 400 Cyrillic charactersshort[]Basic Latin, Extended Latinshort[]Default + Greek and Copticshort[]Default + Hiragana, Katakana, Half-Width, Selection of 2999 Ideographsshort[]Default + Korean charactersshort[]Default + Thai charactersshort[]Default + Vietnamese charactersbooleanMarked as Locked by ImGui::NewFrame() so attempt to modify the atlas will assert.getTexDataAsAlpha8(ImInt outWidth, ImInt outHeight) 1 byte-per-pixelgetTexDataAsAlpha8(ImInt outWidth, ImInt outHeight, ImInt outBytesPerPixel) 1 byte-per-pixelgetTexDataAsRGBA32(ImInt outWidth, ImInt outHeight) 4 bytes-per-pixelgetTexDataAsRGBA32(ImInt outWidth, ImInt outHeight, ImInt outBytesPerPixel) 4 bytes-per-pixelintPadding between glyphs within texture in pixels.intMaximum desired atlas texture height (must be power of two).intMaximum desired atlas texture width (must be power of two).intMinimum desired atlas texture height (must be power of two).intMinimum desired atlas texture width (must be power of two).booleanhasFlags(int flags) Build flags (seeImFontAtlasFlags)booleanisBuilt()voidremoveFlags(int flags) Build flags (seeImFontAtlasFlags)voidsetFlags(int value) Build flags (seeImFontAtlasFlags)voidsetFreeTypeRenderer(boolean enabled) BINDING NOTICE: This method is specific to the imgui-java binding.voidsetLocked(boolean value) Marked as Locked by ImGui::NewFrame() so attempt to modify the atlas will assert.voidsetTexGlyphPadding(int value) Padding between glyphs within texture in pixels.voidsetTexID(long textureID) User data to refer to the texture once it has been uploaded to user's graphic systems.voidsetTexMaxHeight(int value) Maximum desired atlas texture height (must be power of two).voidsetTexMaxWidth(int value) Maximum desired atlas texture width (must be power of two).voidsetTexMinHeight(int value) Minimum desired atlas texture height (must be power of two).voidsetTexMinWidth(int value) Minimum desired atlas texture width (must be power of two).Methods inherited from class imgui.binding.ImGuiStructDestroyable
destroyMethods inherited from class imgui.binding.ImGuiStruct
isNotValidPtr, isValidPtr
-
Constructor Details
-
ImFontAtlas
public ImFontAtlas() -
ImFontAtlas
public ImFontAtlas(long ptr)
-
-
Method Details
-
create
protected long create()- Specified by:
createin classImGuiStructDestroyable
-
addFont
-
addFontDefault
-
addFontDefault
-
addFontDefaultVector
Embedded scalable (vector) default font — recommended at any higher size. (since imgui 1.92) -
addFontDefaultVector
Embedded scalable (vector) default font — recommended at any higher size. (since imgui 1.92) -
addFontDefaultBitmap
Embedded classic pixel-clean bitmap default font — recommended at size 13px with no scaling. (since imgui 1.92) -
addFontDefaultBitmap
Embedded classic pixel-clean bitmap default font — recommended at size 13px with no scaling. (since imgui 1.92) -
addFontFromFileTTF
-
addFontFromFileTTF
-
addFontFromFileTTF
public ImFont addFontFromFileTTF(String filename, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges) -
addFontFromFileTTF
-
addFontFromMemoryTTF
Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed. -
addFontFromMemoryTTF
Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed. -
addFontFromMemoryTTF
public ImFont addFontFromMemoryTTF(byte[] fontData, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed. -
addFontFromMemoryTTF
Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed. -
addFontFromMemoryTTF
Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed. -
addFontFromMemoryTTF
public ImFont addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels, ImFontConfig fontConfig) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed. -
addFontFromMemoryTTF
public ImFont addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed. -
addFontFromMemoryTTF
public ImFont addFontFromMemoryTTF(byte[] fontData, int fontDataSize, float sizePixels, short[] glyphRanges) Note: Transfer ownership of 'ttf_data' to ImFontAtlas! Will be deleted after destruction of the atlas. Set font_cfg.FontDataOwnedByAtlas=false to keep ownership of your data and it won't be freed. -
addFontFromMemoryCompressedTTF
'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp. -
addFontFromMemoryCompressedTTF
public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels, ImFontConfig imFontConfig) 'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp. -
addFontFromMemoryCompressedTTF
public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels, ImFontConfig imFontConfig, short[] glyphRanges) 'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp. -
addFontFromMemoryCompressedTTF
public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, float sizePixels, short[] glyphRanges) 'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp. -
addFontFromMemoryCompressedTTF
public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels) 'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp. -
addFontFromMemoryCompressedTTF
public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels, ImFontConfig imFontConfig) 'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp. -
addFontFromMemoryCompressedTTF
public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels, ImFontConfig imFontConfig, short[] glyphRanges) 'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp. -
addFontFromMemoryCompressedTTF
public ImFont addFontFromMemoryCompressedTTF(byte[] compressedFontData, int compressedFontDataSize, float sizePixels, short[] glyphRanges) 'compressed_font_data' still owned by caller. Compress with binary_to_compressed_c.cpp. -
addFontFromMemoryCompressedBase85TTF
public ImFont addFontFromMemoryCompressedBase85TTF(String compressedFontDataBase85, float sizePixels, ImFontConfig fontConfig) 'compressed_font_data_base85' still owned by caller. Compress with binary_to_compressed_c.cpp with -base85 parameter. -
addFontFromMemoryCompressedBase85TTF
public ImFont addFontFromMemoryCompressedBase85TTF(String compressedFontDataBase85, float sizePixels, ImFontConfig fontConfig, short[] glyphRanges) 'compressed_font_data_base85' still owned by caller. Compress with binary_to_compressed_c.cpp with -base85 parameter. -
clearInputData
public void clearInputData()Clear input data (all ImFontConfig structures including sizes, TTF data, glyph ranges, etc.) = all the data used to build the texture and fonts. -
clearTexData
public void clearTexData()Clear output texture data (CPU side). Saves RAM once the texture has been copied to graphics memory. -
clearFonts
public void clearFonts()Clear output font data (glyphs storage, UV coordinates). -
clear
public void clear()Clear all input and output. -
setFreeTypeRenderer
public void setFreeTypeRenderer(boolean enabled) BINDING NOTICE: This method is specific to the imgui-java binding.Since FreeType is included in the final build, it's possible to use both font renderers (STB_TrueType and FreeType) simultaneously without needing to rebuild the library. By default, we use small hacks to set STB_TrueType as the default font renderer. However, this method allows you to enforce the use of the FreeType renderer.
This method MUST be called before invoking the "#build" or "#getTexData*" methods.
- Parameters:
enabled- true to enable the FreeType font renderer
-
build
public boolean build()Build pixels data. This is called automatically for you by the GetTexData*** functions. -
getTexDataAsAlpha8
1 byte-per-pixel -
getTexDataAsAlpha8
1 byte-per-pixel -
getTexDataAsRGBA32
4 bytes-per-pixel -
getTexDataAsRGBA32
4 bytes-per-pixel -
isBuilt
public boolean isBuilt() -
setTexID
public void setTexID(long textureID) User data to refer to the texture once it has been uploaded to user's graphic systems. It is passed back to you during rendering via the ImDrawCmd structure. -
getGlyphRangesDefault
public short[] getGlyphRangesDefault()Basic Latin, Extended Latin -
getGlyphRangesGreek
public short[] getGlyphRangesGreek()Default + Greek and Coptic -
getGlyphRangesKorean
public short[] getGlyphRangesKorean()Default + Korean characters -
getGlyphRangesJapanese
public short[] getGlyphRangesJapanese()Default + Hiragana, Katakana, Half-Width, Selection of 2999 Ideographs -
getGlyphRangesChineseFull
public short[] getGlyphRangesChineseFull()Default + Half-Width + Japanese Hiragana/Katakana + full set of about 21000 CJK Unified Ideographs -
getGlyphRangesChineseSimplifiedCommon
public short[] getGlyphRangesChineseSimplifiedCommon()Default + Half-Width + Japanese Hiragana/Katakana + set of 2500 CJK Unified Ideographs for common simplified Chinese -
getGlyphRangesCyrillic
public short[] getGlyphRangesCyrillic()Default + about 400 Cyrillic characters -
getGlyphRangesThai
public short[] getGlyphRangesThai()Default + Thai characters -
getGlyphRangesVietnamese
public short[] getGlyphRangesVietnamese()Default + Vietnamese characters -
addCustomRectRegular
public int addCustomRectRegular(int width, int height) -
addCustomRectFontGlyph
Id needs to be<0x110000 to register a rectangle to map into a specific font. -
addCustomRectFontGlyph
public int addCustomRectFontGlyph(ImFont imFont, short id, int width, int height, float advanceX, ImVec2 offset) Id needs to be<0x110000 to register a rectangle to map into a specific font. -
addCustomRectFontGlyph
public int addCustomRectFontGlyph(ImFont imFont, short id, int width, int height, float advanceX, float offsetX, float offsetY) Id needs to be<0x110000 to register a rectangle to map into a specific font. -
getFlags
public int getFlags()Build flags (seeImFontAtlasFlags) -
setFlags
public void setFlags(int value) Build flags (seeImFontAtlasFlags) -
addFlags
public void addFlags(int flags) Build flags (seeImFontAtlasFlags) -
removeFlags
public void removeFlags(int flags) Build flags (seeImFontAtlasFlags) -
hasFlags
public boolean hasFlags(int flags) Build flags (seeImFontAtlasFlags) -
getTexMinWidth
public int getTexMinWidth()Minimum desired atlas texture width (must be power of two). Default 512. (since imgui 1.92 — replaces the old TexDesiredWidth; set TexMinWidth = TexMaxWidth to pin a specific width.) -
setTexMinWidth
public void setTexMinWidth(int value) Minimum desired atlas texture width (must be power of two). Default 512. (since imgui 1.92 — replaces the old TexDesiredWidth; set TexMinWidth = TexMaxWidth to pin a specific width.) -
getTexMinHeight
public int getTexMinHeight()Minimum desired atlas texture height (must be power of two). Default 128. (since imgui 1.92) -
setTexMinHeight
public void setTexMinHeight(int value) Minimum desired atlas texture height (must be power of two). Default 128. (since imgui 1.92) -
getTexMaxWidth
public int getTexMaxWidth()Maximum desired atlas texture width (must be power of two). Default 8192. (since imgui 1.92) Increase when loading large glyph sets (e.g. full CJK) on legacy backends withoutImGuiBackendFlags_RendererHasTexturessupport. -
setTexMaxWidth
public void setTexMaxWidth(int value) Maximum desired atlas texture width (must be power of two). Default 8192. (since imgui 1.92) Increase when loading large glyph sets (e.g. full CJK) on legacy backends withoutImGuiBackendFlags_RendererHasTexturessupport. -
getTexMaxHeight
public int getTexMaxHeight()Maximum desired atlas texture height (must be power of two). Default 8192. (since imgui 1.92) -
setTexMaxHeight
public void setTexMaxHeight(int value) Maximum desired atlas texture height (must be power of two). Default 8192. (since imgui 1.92) -
getTexGlyphPadding
public int getTexGlyphPadding()Padding between glyphs within texture in pixels. Defaults to 1. If your rendering method doesn't rely on bilinear filtering you may set this to 0. -
setTexGlyphPadding
public void setTexGlyphPadding(int value) Padding between glyphs within texture in pixels. Defaults to 1. If your rendering method doesn't rely on bilinear filtering you may set this to 0. -
getLocked
public boolean getLocked()Marked as Locked by ImGui::NewFrame() so attempt to modify the atlas will assert. -
setLocked
public void setLocked(boolean value) Marked as Locked by ImGui::NewFrame() so attempt to modify the atlas will assert.
-