Weird black pixels around TTF text

The title says it all, here is an example:
image

And here is the code that I’m using:
SDL_Texture* loadText(std::string textureText[], SDL_Color textColor, int tTC, int width, int height)
{
int texty = 0;
SDL_Texture* textTexture = NULL;
SDL_Surface* textSurface = NULL;
textSurface = SDL_CreateRGBSurface(0,width,height,32,0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
SDL_Rect rect;
for(int i = 0; i < tTC; i++)
{
SDL_Surface* textSurfaceTemp = TTF_RenderText_Blended( gFont, textureText[i].c_str(), textColor );
if(textSurfaceTemp != NULL)
{
rect.x = 0;
rect.y = texty;
rect.h = textSurfaceTemp->h * SCREEN_HEIGHT / 1080.f;
rect.w = textSurfaceTemp->w * SCREEN_WIDTH / 1920.f;
texty += textSurfaceTemp->h * SCREEN_HEIGHT / 1080.f;
SDL_BlitSurface(textSurfaceTemp, NULL, textSurface, &rect);
SDL_FreeSurface(textSurfaceTemp);

		}
	}
	textTexture = SDL_CreateTextureFromSurface(gRenderer, textSurface);
	SDL_FreeSurface(textSurface);
	textSurface = NULL;
	return textTexture;
}

The color used for textColor = 255,255,255. tTC is the amount of strings the array textureText contains.
Does anyone know why this causes weird black pixels around the text? Thanks in advance.

Either 1) the surface you create has the wrong format, or 2) The font you’re using is causing it.

I would first try simplifying your method, liike my code below:

TTF_Font* txtfont = GetFont(ResourcePool[Font]);
	Texture = SDL_CreateTextureFromSurface(Renderer, 
		TTF_RenderText_Blended(txtfont, Text, color(255,255,255,255)));
	SDL_QueryTexture(Texture, NULL, NULL, &Width, &Height);
	SrcRect = rect(0,0,Width,Height);
	DestRect = rect((int)fX, (int)fY, Width, Height);

Secondly, if that doesn’t solve it, try a different font. Try a couple different fonts.

Will do, another thing I’ve been thinking about, you could also make the text non anti aliased and 8x bigger than requested format. That way, you’ll size it down and texture filtering will do the smoothing.

I have found the problem, when directly converting the text surface into a texture everything seems okay.
When doing it my way, SDL_BlitSurface(textSurfaceTemp, NULL, textSurface, &rect); causes alpha value of letter edges to turn dark.
How can I fix this or do it without SDL_BlitSurface();?

I fixed it by putting SDL_FillRect(textSurface, NULL, SDL_MapRGBA(textSurface->format, textColor.r, textColor.g, textColor.b, 0)); after
textSurface = SDL_CreateRGBSurface(0,width,height,32,0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);

Final result:
SDL_Texture* loadText(std::string textureText[], SDL_Color textColor, int tTC, int width, int height)
{
int texty = 0;
int w = 0;
int h = 0;
SDL_Texture* textTexture = NULL;
SDL_Surface* textSurface = NULL;
textSurface = SDL_CreateRGBSurface(0,width,height,32,0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
SDL_FillRect(textSurface, NULL, SDL_MapRGBA(textSurface->format, textColor.r, textColor.g, textColor.b, 0));
SDL_Rect rect;
for(int i = 0; i < tTC; i++)
{
TTF_SizeText(gFont, textureText[i].c_str(), &w, &h);
rect.x = 0;
rect.y = texty;
rect.h = h * SCREEN_HEIGHT / 1080.f;
rect.w = w * SCREEN_WIDTH / 1920.f;
texty += h * SCREEN_HEIGHT / 1080.f;
SDL_BlitSurface(TTF_RenderText_Blended(gFont, textureText[i].c_str(), textColor), NULL, textSurface, &rect);
}
textTexture = SDL_CreateTextureFromSurface(gRenderer, textSurface);
SDL_FreeSurface(textSurface);
textSurface = NULL;
return textTexture;
}

Have you tried using TTF_SetFontHinting???