Closed JBetz closed 1 month ago
No issue drawing multiple text objects created by the same text engine with different colors:
The blurriness and artifacts should be fixed in https://github.com/libsdl-org/SDL_ttf/commit/3adac8ac7ca3be6a5f73a23d930c9f7449f99189. I'm still not sure what's causing the text to be truncated though.
Are you setting a clip rectangle or anything? I'm not sure why it would work in the editor, but not in your button.
I am, and indeed that's probably the issue.
My rectangles have float coordinates when then get truncated to integers to create a SDL_Rect
when clipping. For static text, the origin is determined by a layout engine which returns float
s, and then the extent is calculated with TTF_GetTextSubStringsForRange
which returns int
s.
I'll need to play with it some more because even if I round x
and y
down and width
and height
up for the clip rectangle, it still doesn't quite fit.
FWIW, I noticed that if I round the x
and y
parameters passed to TTF_DrawRendererText
(i.e., convert from float
to int
), the artifacts go away:
I haven't tested your fix yet but will soon.
Yeah, you shouldn't clip the text. Try removing that and grabbing the latest fix, it should work correctly now.
Blur and artifacts are gone, but now some of the glyphs have bits missing. Oddly, the e
in the north east slot looks fine while all the others don't.
If I truncate the x
and y
parameters passed to TTF_DrawRendererText
, it looks perfect:
Yeah, since the text is pixel perfect, it should be drawn on pixel boundaries. We don't mess with the coordinates passed in, because there might be scaling applied, but you want it aligned with the output.
That makes sense. Thanks!
I haven't find a reliable way to reproduce this yet, but basically, text sometimes becomes distorted when there are multiple text objects drawn to the same window using the same text engine.
With
SDL_RENDER_DRIVER
set togpu
, the text in the editor is clear but the text in the grid items has some seemingly random artifacts, most notable between thet
ande
glyph insidePaste
:With
SDL_RENDER_DRIVER
set tosoftware
, the text in the grid items is noticeably clearer:Note however that in both cases the rectangle is slightly narrow, which makes me think that this isn't an issue with the GPU renderer but something in the TTF + renderer interface. Or perhaps wrong usage of the text engine on my side.