You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now a new texture is generated for each unique text written using a TTF Font, making the number of texture and drawcall increase really fast when writting a lot of text
OpenGLTexture fontTexture;
TTF_Font * font = TTF_OpenFont(fontPath.c_str(), textSize);
if (not font)
{
LOG_ERROR(DOM, "Font could not be loaded: " << fontPath << ", error: " << TTF_GetError());
return fontTexture;
}
SDL_Color color = {255, 255, 255, 255};
SDL_Surface * sFont = TTF_RenderText_Blended(font, text.c_str(), color);
if (not sFont)
{
LOG_ERROR(DOM, "Font surface could not be generated" << ", error: " << TTF_GetError());
TTF_CloseFont(font);
return fontTexture;
}
auto w = nextpoweroftwo(sFont->w);
auto h = nextpoweroftwo(sFont->h);
auto intermediary = SDL_CreateRGBSurface(0, w, h, 32,
0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);
SDL_BlitSurface(sFont, 0, intermediary, 0);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, intermediary->pixels);
sizeMap[textureName] = TTFSize{w, h};
fontTexture.id = texture;
fontTexture.transparent = false;
SDL_FreeSurface(sFont);
SDL_FreeSurface(intermediary);
TTF_CloseFont(font);
return fontTexture;
The text was updated successfully, but these errors were encountered:
Right now a new texture is generated for each unique text written using a TTF Font, making the number of texture and drawcall increase really fast when writting a lot of text
The text was updated successfully, but these errors were encountered: