I try to display some unicode characters in CImGui, but I am failing.
This is the simple code mainly from the demo.jl:
using GLFW
using ModernGL
using CSyntax
using CSyntax.CStatic
using CImGui
using CImGui.GLFWBackend
using CImGui.OpenGLBackend
@static if Sys.isapple()
# OpenGL 3.2 + GLSL 150
tmp_glsl_version = 150
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MAJOR, 3)
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MINOR, 2)
GLFW.WindowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE) # 3.2+ only
GLFW.WindowHint(GLFW.OPENGL_FORWARD_COMPAT, GL_TRUE) # required on Mac
else
# OpenGL 3.0 + GLSL 130
tmp_glsl_version = 130
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MAJOR, 3)
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MINOR, 0)
# GLFW.WindowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE) # 3.2+ only
# GLFW.WindowHint(GLFW.OPENGL_FORWARD_COMPAT, GL_TRUE) # 3.0+ only
GLFW.WindowHint(GLFW.FOCUSED,GL_TRUE)
end
const glsl_version=tmp_glsl_version
# setup GLFW error callback
error_callback(err::GLFW.GLFWError) = @error "GLFW ERROR: code $(err.code) msg: $(err.description)"
GLFW.SetErrorCallback(error_callback)
# create window
window = GLFW.CreateWindow(1100, 720, "PlayGround")
@assert window != C_NULL
GLFW.MakeContextCurrent(window)
GLFW.SwapInterval(1) # enable vsync
# setup Dear ImGui context
ctx = CImGui.CreateContext()
# setup Dear ImGui style
CImGui.StyleColorsClassic()
#
# start to build th font:
#
builder=CImGui.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder()
CImGui.ImFontGlyphRangesBuilder_AddText(builder,"????","")
CImGui.ImFontGlyphRangesBuilder_AddChar(builder,'?')
CImGui.ImFontGlyphRangesBuilder_AddChar(builder,'?')
CImGui.ImFontGlyphRangesBuilder_AddChar(builder,'?')
CImGui.ImFontGlyphRangesBuilder_AddChar(builder,'?')
ranges=CImGui.ImVector_ImWchar_create()
CImGui.ImFontGlyphRangesBuilder_BuildRanges(builder, ranges)
#fonts_dir = joinpath(pathof(CImGui), "..","..","fonts")
fonts_dir = raw"c:\Windows\Fonts";
fonts = CImGui.GetIO().Fonts
CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "arial.ttf"), 16, C_NULL, ranges )
#CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "arial.ttf"), 16, C_NULL, CImGui.GetGlyphRangesChineseSimplifiedCommon(fonts) )
CImGui.Build(fonts)
default_font = CImGui.AddFontDefault(fonts)
#@assert default_font != C_NULL
# setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true)
ImGui_ImplOpenGL3_Init(glsl_version)
try
clear_color = Cfloat[0.45, 0.55, 0.60, 1.00]
while !GLFW.WindowShouldClose(window)
GLFW.PollEvents()
# start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame()
ImGui_ImplGlfw_NewFrame()
CImGui.NewFrame()
CImGui.SetNextWindowSize(CImGui.ImVec2(350.0,200.0),CImGui.ImGuiCond_Once);
CImGui.Begin("Special strings")
CImGui.Text("????")
CImGui.Text("p ? ? ? ?")
CImGui.End()
# rendering
CImGui.Render()
GLFW.MakeContextCurrent(window)
display_w, display_h = GLFW.GetFramebufferSize(window)
glViewport(0, 0, display_w, display_h)
glClearColor(clear_color...)
glClear(GL_COLOR_BUFFER_BIT)
ImGui_ImplOpenGL3_RenderDrawData(CImGui.GetDrawData())
GLFW.MakeContextCurrent(window)
GLFW.SwapBuffers(window)
end
catch e
@error "Error in renderloop!" exception=e
Base.show_backtrace(stderr, catch_backtrace())
display_close(display)
finally
ImGui_ImplOpenGL3_Shutdown()
ImGui_ImplGlfw_Shutdown()
CImGui.DestroyContext(ctx)
GLFW.DestroyWindow(window)
end
It fails with the following error:
Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ACCESS_VIOLATION at 0x70c4fe49 -- _ZN5ImGui14SetCurrentFontEP6ImFont at C:\Users\Oli\.julia\artifacts\d47e9affaed6dd0e59dff721ebb86dd8347b057f\bin\libimgui-cpp.dll (unknown line)
in expression starting at REPL[41]:1
_ZN5ImGui14SetCurrentFontEP6ImFont at C:\Users\Oli\.julia\artifacts\d47e9affaed6dd0e59dff721ebb86dd8347b057f\bin\libimgui-cpp.dll (unknown line)
_ZN5ImGui8NewFrameEv at C:\Users\Oli\.julia\artifacts\d47e9affaed6dd0e59dff721ebb86dd8347b057f\bin\libimgui-cpp.dll (unknown line)
igNewFrame at C:\Users\Oli\.julia\packages\CImGui\tJ4ZL\gen\libcimgui_api.jl:54 [inlined]
NewFrame at C:\Users\Oli\.julia\packages\CImGui\tJ4ZL\src\wrapper.jl:54 [inlined]
top-level scope at .\REPL[41]:100:
Does anybody know what’s the proper way to display unicode characters in a CImGui window?
The following code works but display only ? for each unicode character:
using GLFW
using ModernGL
using CSyntax
using CSyntax.CStatic
using CImGui
using CImGui.GLFWBackend
using CImGui.OpenGLBackend
@static if Sys.isapple()
# OpenGL 3.2 + GLSL 150
tmp_glsl_version = 150
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MAJOR, 3)
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MINOR, 2)
GLFW.WindowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE) # 3.2+ only
GLFW.WindowHint(GLFW.OPENGL_FORWARD_COMPAT, GL_TRUE) # required on Mac
else
# OpenGL 3.0 + GLSL 130
tmp_glsl_version = 130
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MAJOR, 3)
GLFW.WindowHint(GLFW.CONTEXT_VERSION_MINOR, 0)
# GLFW.WindowHint(GLFW.OPENGL_PROFILE, GLFW.OPENGL_CORE_PROFILE) # 3.2+ only
# GLFW.WindowHint(GLFW.OPENGL_FORWARD_COMPAT, GL_TRUE) # 3.0+ only
GLFW.WindowHint(GLFW.FOCUSED,GL_TRUE)
end
const glsl_version=tmp_glsl_version
# setup GLFW error callback
error_callback(err::GLFW.GLFWError) = @error "GLFW ERROR: code $(err.code) msg: $(err.description)"
GLFW.SetErrorCallback(error_callback)
# create window
window = GLFW.CreateWindow(1100, 720, "PlayGround")
@assert window != C_NULL
GLFW.MakeContextCurrent(window)
GLFW.SwapInterval(1) # enable vsync
# setup Dear ImGui context
ctx = CImGui.CreateContext()
# setup Dear ImGui style
CImGui.StyleColorsClassic()
#
# start to build th font:
#
#builder=CImGui.ImFontGlyphRangesBuilder_ImFontGlyphRangesBuilder()
#CImGui.ImFontGlyphRangesBuilder_AddText(builder,"????","")
#CImGui.ImFontGlyphRangesBuilder_AddChar(builder,'?')
#CImGui.ImFontGlyphRangesBuilder_AddChar(builder,'?')
#CImGui.ImFontGlyphRangesBuilder_AddChar(builder,'?')
#CImGui.ImFontGlyphRangesBuilder_AddChar(builder,'?')
#ranges=CImGui.ImVector_ImWchar_create()
#CImGui.ImFontGlyphRangesBuilder_BuildRanges(builder, ranges)
#fonts_dir = joinpath(pathof(CImGui), "..","..","fonts")
fonts_dir = raw"c:\Windows\Fonts";
fonts = CImGui.GetIO().Fonts
#CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "arial.ttf"), 16, C_NULL, ranges )
CImGui.AddFontFromFileTTF(fonts, joinpath(fonts_dir, "arial.ttf"), 16, C_NULL, CImGui.GetGlyphRangesChineseSimplifiedCommon(fonts) )
CImGui.Build(fonts)
default_font = CImGui.AddFontDefault(fonts)
#@assert default_font != C_NULL
# setup Platform/Renderer bindings
ImGui_ImplGlfw_InitForOpenGL(window, true)
ImGui_ImplOpenGL3_Init(glsl_version)
try
clear_color = Cfloat[0.45, 0.55, 0.60, 1.00]
while !GLFW.WindowShouldClose(window)
GLFW.PollEvents()
# start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame()
ImGui_ImplGlfw_NewFrame()
CImGui.NewFrame()
CImGui.SetNextWindowSize(CImGui.ImVec2(350.0,200.0),CImGui.ImGuiCond_Once);
CImGui.Begin("Special strings")
CImGui.Text("????")
CImGui.Text("p ? ? ? ?")
CImGui.End()
# rendering
CImGui.Render()
GLFW.MakeContextCurrent(window)
display_w, display_h = GLFW.GetFramebufferSize(window)
glViewport(0, 0, display_w, display_h)
glClearColor(clear_color...)
glClear(GL_COLOR_BUFFER_BIT)
ImGui_ImplOpenGL3_RenderDrawData(CImGui.GetDrawData())
GLFW.MakeContextCurrent(window)
GLFW.SwapBuffers(window)
end
catch e
@error "Error in renderloop!" exception=e
Base.show_backtrace(stderr, catch_backtrace())
display_close(display)
finally
ImGui_ImplOpenGL3_Shutdown()
ImGui_ImplGlfw_Shutdown()
CImGui.DestroyContext(ctx)
GLFW.DestroyWindow(window)
end