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

Fix texture-based anti-aliasing with RGBA textures #5132

Closed
wants to merge 1 commit into from

Conversation

cfillion
Copy link
Contributor

@cfillion cfillion commented Mar 23, 2022

Texture-based anti-aliasing is broken after loading a font using imgui_freetype.cpp with ImGuiFreeTypeBuilderFlags_LoadColor set in ImFontConfig::FontBuilderFlags. Using the OpenGL3 backend (haven't tested others).

Screenshot of the bug

#define IMGUI_ENABLE_FREETYPE
// ...
ImFontConfig cfg;
cfg.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_LoadColor;
io.Fonts->AddFontFromFileTTF("/usr/share/fonts/TTF/DejaVuSans.ttf", 14, &cfg);

This appears to be because ImFontAtlasBuildRenderLinesTexData uses transparent black when writing to TexPixelsRGBA32. Transparent white is produced (via GetTexDataAsRGBA32) when it writes to TexPixelsAlpha8.

This PR removes that difference by having ImFontAtlasBuildRenderLinesTexData write transparent white to TexPixelsRGBA32. It restores anti-aliasing (although I don't fully understand why, so I'm not 100% certain whether this is the correct fix):

Patched to write transparent white

When using an Alpha8 font texture, GetTexDataAsRGBA32 converts 0x00 to transparent white.

When using a RGBA32 font texture, ImFontAtlasBuildRenderLinesTexData was writing transparent black.
ocornut pushed a commit that referenced this pull request Mar 23, 2022
…#3245)

When using an Alpha8 font texture, GetTexDataAsRGBA32 converts 0x00 to transparent white.
When using a RGBA32 font texture, ImFontAtlasBuildRenderLinesTexData was writing transparent black.
@ocornut
Copy link
Owner

ocornut commented Mar 23, 2022

Nice catch, thank you!
Merged as 7d7bf99

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants