Reputation: 217
im currently facing an strange error with rendering text using SDL_TTF and OpenGL.
The thing is that when i use TTF_RenderText_Blended , all texts are displayed good and without any problems
But when i want switch to TTF_RenderText_Solid "buggy" black rectangles are displayed and i dont know specify if its problem with SDL_TTF or in OpenGL when creating the right texture from surface
Function to load surface from textInfo(font,size)
void TextSprite::loadSprite(const std::string& text, textInfo* info){
SDL_Surface* tmpSurface = nullptr;
tmpSurface = TTF_RenderText_Solid(info->font,text.c_str(), *_color);
if (tmpSurface==nullptr){
ErrorManager::systemError("Cannot make a text texture");
}
createTexture(tmpSurface);
}
Function to create an OpenGL texture from SDL_Surface
void TextSprite::createTexture(SDL_Surface* surface){
glGenTextures(1,&_textureID);
glBindTexture(GL_TEXTURE_2D,_textureID);
int Mode = GL_RGB;
if (surface->format->BytesPerPixel==4){
Mode = GL_RGBA;
}
glTexImage2D(GL_TEXTURE_2D,0,Mode,surface->w,surface->h,0,Mode,GL_UNSIGNED_BYTE,surface->pixels);
//Wrapping
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
//Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glBindTexture(GL_TEXTURE_2D,0);
_rect.w = surface->w;
_rect.h = surface->h;
SDL_FreeSurface(surface);
}
Thanks for help.
Upvotes: 1
Views: 918
Reputation: 52083
TTF_RenderText_Solid()
outputs 8-bit palettized surfaces, not the 32-bit ARGB surfaces that TextSprite::createTexture()
operates on.
Upvotes: 2