Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Custom nerdfont displays as ? for short period before displaying #693

Closed
damntourists opened this issue Sep 1, 2023 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@damntourists
Copy link

What happend?

Hi there, Before I display anything in my app, I load a couple additional fonts that I obtained from https://www.nerdfonts.com/ and set one of them as a default font. This happens in init() so they should be loaded before the main function executes. I noticed that for approximately 1-2 seconds after the window displays, the font doesn't render, so instead it shows as "?" briefly. Have you ever encountered this? Is there a known way to get around this?

Code example

main.go
// put your code here!

To Reproduce

  1. Run my demo
  2. will see the crash...

Version

master

OS

ubuntu

@damntourists damntourists added the bug Something isn't working label Sep 1, 2023
@gucio321
Copy link
Collaborator

gucio321 commented Sep 1, 2023

sounds strange
It may be because of RebuildFontAtlas needs some time to build fonts so if you're initializing more fonts, it may take a bit longer to build it all
If you want to get rid of this effect, I'd suggest using imgui's font api instead of giu's one

@damntourists
Copy link
Author

Okay! I'll take a look and see what I can do. Thanks for your input!

@damntourists
Copy link
Author

damntourists commented Sep 1, 2023

Actually, not sure if this is intentional or not, but it looks like when the master window renders, it runs:


func (w *MasterWindow) render() {
	if !w.platform.IsVisible() || w.platform.IsMinimized() {
		return
	}

	Context.invalidAllState()
	defer Context.cleanState()

	rebuildFontAtlas()     <========= returns immediately on first run

	p := w.platform
	r := w.renderer

	p.NewFrame()
	r.PreRender(w.clearColor)

	imgui.NewFrame()
	w.updateFunc()
	imgui.Render()

	r.Render(p.DisplaySize(), p.FramebufferSize(), imgui.RenderedDrawData())
	p.PostRender()
}

The part that causes it to return immediately, since rebuildFontAtlas is only defined as a variable at this point, not actually set:

// Rebuild font atlas when necessary.
func rebuildFontAtlas() {
	if !shouldRebuildFontAtlas {
		return
	}

So imgui.Render() executes before the rebuilding of the Font atlas occurs. Eventually it hits the PostRender() function, and the first frame is drawn without ever having rebuilt the font atlas.

// PostRender performs a buffer swap.
func (platform *GLFW) PostRender() {
	platform.window.SwapBuffers()
}

The only way shouldRebuildFontAtlas seems to get set is by running functions SetSize and tStr.

@gucio321
Copy link
Collaborator

gucio321 commented Sep 1, 2023

yes, its intentional. Its because of how FontAtlas works.
it collects data about all characters that needs to be rendered in your app and then includes only these charactes as GlyphRanges argument to imgui.AddFont*
thats why imgui needs to be rendered at least once before fonts are build

@gucio321 gucio321 closed this as completed Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants