[SDL] <DKIM> Strange artefacts on SDL text backgrounds

Sanette sanette-linux at laposte.net
Sat Sep 6 03:48:34 PDT 2014


in method B, since the TTF texture has transparent pixels, I would do a 
SDL_RenderClear(renderer) just after
SDL_SetRenderTarget. Otherwise you might have random pixels in the 
background.
If you want to preserve transparency, you may also do a 
SDL_SetRenderDrawColor(renderer,0,0,0,0) before SDL_RenderClear.


Le 06/09/2014 12:01, Sagara Wijetunga a écrit :
> How do use SDL2_ttf is as follows:
>
> 1. Method A
> surface = TTF_RenderUTF8_Blended(font, "Text", colour);
> texture = SDL_CreateTextureFromSurface(renderer, surface);
> SDL_RenderCopy(..texture..);
>
> No issue.
>
> 2. Method B
> surfaceOrig = TTF_RenderUTF8_Blended(fontTitle, "Text", colour);
> textureOrig = SDL_CreateTextureFromSurface(renderer, surfaceOrig);
>
> textureScaled = SDL_CreateTexture(renderer, pixFormatOrig, 
> SDL_TEXTUREACCESS_TARGET, w, h);
> SDL_SetRenderTarget(renderer, textureScaled);
> SDL_RenderCopy(renderer, textureOrig, NULL, NULL)
> SDL_SetRenderTarget(renderer, NULL);
> SDL_RenderCopy(..textureScaled..);
>
> Only in this path I have issues.
>
> Note 1, test program for Method B does not show any issue.
>
> Note 2, texture returned from SDL_CreateTexture() is not validated in 
> any way other than for a valid pointer. If necessary to validate, what 
> should I do?
>
> Thanks.
>
> Sagara
> On Saturday, September 6, 2014 11:57 AM, Sanette 
> <sanette-linux at laposte.net> wrote:
>
>
> how do you render your ttf ?
> usually SDL_tt will generate a surface, and then you either render the 
> surface onscreen, or to a target texture which is then rendered onscreen.
> In the latter case, did you check that your target texture was 
> initialized (filled) with zeros ?
>
> 1. Method A
> surface = TTF_RenderUTF8_Blended(font, "Text", colour);
> texture = SDL_CreateTextureFromSurface(renderer, surface);
> SDL_RenderCopy(..texture..);
>
> No issue.
>
> 2. Method B
> surfaceOrig = TTF_RenderUTF8_Blended(fontTitle, "Text", colour);
> textureOrig = SDL_CreateTextureFromSurface(renderer, surfaceOrig);
>
> textureScaled = SDL_CreateTexture(renderer, pixFormatOrig, 
> SDL_TEXTUREACCESS_TARGET, w, h);
> SDL_SetRenderTarget(renderer, textureScaled);
> SDL_RenderCopy(renderer, textureOrig, NULL, NULL)
> SDL_SetRenderTarget(renderer, NULL);
> SDL_RenderCopy(..textureScaled..);
>
> Only in this path I have issues.
>>
>>
>>
>> _______________________________________________
>> SDL mailing list
>> SDL at lists.libsdl.org  <mailto:SDL at lists.libsdl.org>
>> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20140906/c15adc76/attachment-0002.htm>


More information about the SDL mailing list