You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am new to ImGui and I am trying to make a log window that shows the log messages I receive in the console:
As you can see, the log messages contain emojis and I'd like to display them too. Right now, It shows them as question marks:
I tried searching online and from this documentation of ImGui and this documentation of pyimgui it seems that I need to load a custom font with glyph ranges.
Loading a simple font with io.font.add_font_from_file_ttf(font, 16) works just fine, but when I try to add glyphs with io.fonts.get_glyph_ranges_chinese() or something similar, it just crashes and I don't understand why.
I am using pygame as a backend (pygame-ce actually). Here's the sample code I tried to use:
fromimgui.integrations.pygameimportPygameRendererimportimguiimportmodernglasmglimportpygamedefmain():
pygame.init()
pygame.display.gl_set_attribute(
pygame.GL_CONTEXT_PROFILE_MASK, pygame.GL_CONTEXT_PROFILE_CORE
)
size=1600, 900pygame.display.set_mode(size, pygame.DOUBLEBUF|pygame.OPENGL)
ctx=mgl.create_context(require=330)
context=imgui.create_context()
impl=PygameRenderer()
clock=pygame.time.Clock()
io=imgui.get_io()
io.display_size=sizef=io.fonts.add_font_from_file_ttf(
r"C:\Windows\Fonts\calibri.ttf", # Just a sample font16,
io.fonts.get_glyph_ranges_chinese(), # Adding this causes ImGui to crash!
)
impl.refresh_font_texture()
show_custom_window=True# Note the emoji at the endexample_msg="12.10.2023 18:00:35.464 | INFO ℹ️ |"running=Truewhilerunning:
foreventinpygame.event.get():
ifevent.type==pygame.QUIT:
running=Falseimpl.process_event(event)
impl.process_inputs()
imgui.new_frame()
ifimgui.begin_main_menu_bar():
ifimgui.begin_menu("File", True):
clicked_quit, selected_quit=imgui.menu_item(
"Quit", "Ctrl+Q", False, True
)
ifclicked_quit:
running=Falseimgui.end_menu()
imgui.end_main_menu_bar()
imgui.show_test_window()
ifshow_custom_window:
is_expand, show_custom_window=imgui.begin("Custom window", True)
ifis_expand:
imgui.text(example_msg) # Doesn't work with normal fontwithimgui.font(f): # Doesn't work without the third argument which I can't get to workimgui.text(example_msg)
imgui.end()
ctx.clear(0.08, 0.16, 0.18)
imgui.render()
impl.render(imgui.get_draw_data())
pygame.display.flip()
clock.tick(60)
impl.shutdown()
imgui.destroy_context(context)
ctx.release()
pygame.quit()
if__name__=="__main__":
main()
I don't understand why adding io.fonts.get_glyph_ranges_chinese() causes it to crash because it seems to be the correct way to add glyph ranges. What am I missing here? How can I fix this code to render emojis correctly?
The text was updated successfully, but these errors were encountered:
I am new to ImGui and I am trying to make a log window that shows the log messages I receive in the console:
As you can see, the log messages contain emojis and I'd like to display them too. Right now, It shows them as question marks:
I tried searching online and from this documentation of ImGui and this documentation of
pyimgui
it seems that I need to load a custom font with glyph ranges.Loading a simple font with
io.font.add_font_from_file_ttf(font, 16)
works just fine, but when I try to add glyphs withio.fonts.get_glyph_ranges_chinese()
or something similar, it just crashes and I don't understand why.I am using
pygame
as a backend (pygame-ce
actually). Here's the sample code I tried to use:I don't understand why adding
io.fonts.get_glyph_ranges_chinese()
causes it to crash because it seems to be the correct way to add glyph ranges. What am I missing here? How can I fix this code to render emojis correctly?The text was updated successfully, but these errors were encountered: