I’m trying two ways to cache SDL_tttf glyphs.
First way is by creating an array of textures from the surface returned by
TTF_RenderGlyph_Blended() and render each glyph that I need from the array, and here is the result of that:
Second way is by creating a texture atlas with
SDL_BLENDMODE_BLEND and render the individual textures from the array before and just crop the glyph that I need from the texture atlas when I need to render, and here is the result of that:
I don’t know if you can see it properly but the second picture has lower quality glyphs, and I don’t know why that is and if anyone has a better way to cache please tell.
I looked at your two PNGs and it looks to me like it’s just the anti-aliasing around the characters that is different? All I could think of checking is the pixel format of your texture alias (does it need to be SDL_PIXELFORMAT_RGBA8888?) and does it need to be cleared to RGBA 0000 after you created it? Or maybe it’s a problem with how you are blending to the texture atlas, or from the texture atlas to the screen?
SDL_QueryTexture to one of the textures in the array to get the format and use that for creating the texture atlas, and as for the other things that you said, I will have to do some testing, thanks.
My guess is that the alpha channel is being applied twice (i.e. the final render corresponds to
alpha*alpha). This is the kind of thing that can happen if you transfer via an intermediate texture and the alpha is applied at both steps (glyph->atlas and atlas->target). I would check your blend modes; you probably don’t want to be blending the glyph into the atlas but simply copying it.
All I had to do was set the glyph texture’s blend mode to
SDL_BLENDMODE_NONE before rendering it to the atlas, thanks guys.