Hello,
I’m trying to write texts on transparent buttons so on transparent texture.
I first display an image like follow:
SDL_Surface* surface = IMG_Load( imgName );
widget->backgroundImage = SDL_CreateTextureFromSurface( renderer, surface );
Then I create a texture for by button where I’ll be able to draw:
widget->texture = SDL_CreateTexture(
renderer,
SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_TARGET,
widget->size.w,
widget->size.h);
SDL_SetTextureBlendMode(widget->texture, SDL_BLENDMODE_BLEND);
Then I draw my background image in the widget’s texture:
SDL_SetRenderTarget(renderer, widget->texture);
SDL_SetRenderDrawColor(renderer, (Uint8) widget->backgroundColor.r, (Uint8) widget->backgroundColor.g, (Uint8) widget->backgroundColor.b, (Uint8) widget->backgroundColor.a);
SDL_RenderClear(renderer);
SDL_RenderCopy( renderer, widget->backgroundImage, &src, &dst );
Finally I want to draw a label on my button:
SDL_Surface *txtSurf = TTF_RenderUTF8_Blended(font, string, textColor); // font is arial.ttf
SDL_Texture *strTexture = SDL_CreateTextureFromSurface(renderer, txtSurf );
SDL_FreeSurface( txtSurf );
SDL_SetTextureBlendMode(strTexture, SDL_BLENDMODE_BLEND); // also tried SDL_BLENDMODE_NONE
SDL_RenderCopy( renderer, strTexture, &src, &dest );
SDL_DestroyTexture(strTexture);
I made a test with a transparent background image (SPORT) and an opaque background image (FITNESS) and here is the result:
We clearly see on this screenshot that the text displayed on transparent image (SPORT) is of bad quality compare to ‘FITNESS’ displayed on opaque texture.
How to solve this problem??
Al