From cf6b39600bfbceb0c404cb8607b49f30a8fdc4e6 Mon Sep 17 00:00:00 2001 From: omar Date: Mon, 5 Feb 2018 11:21:06 +0100 Subject: [PATCH] imgui_freetype: comments about correct blending and sRGB (#618, #578) --- misc/freetype/README.md | 6 ++++++ misc/freetype/imgui_freetype.cpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/misc/freetype/README.md b/misc/freetype/README.md index 8b5d01d4..ad0e4d3b 100644 --- a/misc/freetype/README.md +++ b/misc/freetype/README.md @@ -17,6 +17,12 @@ ImGuiFreeType::BuildFontAtlas(io.Fonts, flags); io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); ``` +**Gamma Correct Blending** +FreeType assumes blending in linear space rather than gamma space. +See FreeType note for [FT_Render_Glyph](https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Render_Glyph). +For correct results you need to be using sRGB and convert to linear space in the pixel shader output. +The default imgui styles will be impacted by this change (alpha values will need tweaking). + **Test code Usage** ```cpp #include "misc/freetype/imgui_freetype.h" diff --git a/misc/freetype/imgui_freetype.cpp b/misc/freetype/imgui_freetype.cpp index 9a04ed89..9e373c7d 100644 --- a/misc/freetype/imgui_freetype.cpp +++ b/misc/freetype/imgui_freetype.cpp @@ -10,6 +10,12 @@ // - v0.54: (2018/01/22) fix for addition of ImFontAtlas::TexUvscale member // - v0.55: (2018/02/04) moved to main imgui repository (away from http://www.github.com/ocornut/imgui_club) +// Gamma Correct Blending: +// FreeType assumes blending in linear space rather than gamma space. +// See https://www.freetype.org/freetype2/docs/reference/ft2-base_interface.html#FT_Render_Glyph +// For correct results you need to be using sRGB and convert to linear space in the pixel shader output. +// The default imgui styles will be impacted by this change (alpha values will need tweaking). + // TODO: // - Output texture has excessive resolution (lots of vertical waste) // - FreeType's memory allocator is not overridden.