Hey guys,
I am trying to blend text that was created by SDL_TTF onto another texture using alpha blending. However that creates strange borders arround the text (pixels that are way too dark), which can be seen in the picture. It shows two textures, the first one is the “text texture” drawn directly and the second one is the “blenden texture”, where the “text texture” has first been drawn onto another empty texture, which then is rendererd.
[Image: http://i.imgur.com/oPctOLk.png ]
The code to create this picture looks like the following:
Code:
//creating the "text texture"
SDL_Color textCol = { 255, 0, 0, 255 };
SDL_Surface* textSurface = TTF_RenderText_Blended(resourceManager->getFont(“arial”, 20), “Test”, textCol);
SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface);
SDL_SetTextureBlendMode(textTexture, SDL_BLENDMODE_BLEND);
SDL_FreeSurface(textSurface);
int textWidth, textHeight;
SDL_QueryTexture(textTexture, NULL, NULL, &textWidth, &textHeight);
//creating a new and empty texture and drawing the “text texture” ontop of it
SDL_Texture* blendedTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, textWidth, textHeight);
SDL_SetTextureBlendMode(blendedTexture, SDL_BLENDMODE_BLEND);
SDL_SetRenderTarget(renderer, blendedTexture);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
SDL_Rect renderRect = SDL_Rect{ 0, 0, textWidth, textHeight };
SDL_RenderCopy(renderer, textTexture, NULL, &renderRect);
SDL_SetRenderTarget(renderer, NULL);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
//finally rendering both textures to compare them
renderRect = SDL_Rect{ 100, 250, textWidth, textHeight };
SDL_RenderCopy(renderer, textTexture, NULL, &renderRect);
renderRect = SDL_Rect{ 100, 270, textWidth, textHeight };
SDL_RenderCopy(renderer, blendedTexture, NULL, &renderRect);
As you can see I set for almost everything (textures and renderer) the blend mode to blend, I also tried setting the alpha mod of the textures but nothing made both textures look the same. Is there something I’m missing or is there something wrong with what I’m doing here? Please help
Thanks in advance!