【问题标题】:TTF_RenderText_Solid errorTTF_RenderText_Solid 错误
【发布时间】:2016-12-03 00:05:54
【问题描述】:

我目前在使用 SDL_TTF 和 OpenGL 渲染文本时遇到了一个奇怪的错误。

问题是当我使用 TTF_RenderText_Blended 时,所有文本都显示良好且没有任何问题

但是当我想切换到 TTF_RenderText_Solid 时会显示“错误”黑色矩形,我不知道在从表面

从 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);

}

从 SDL_Surface 创建 OpenGL 纹理的函数

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);

}

感谢您的帮助。

【问题讨论】:

    标签: c++ opengl sdl


    【解决方案1】:

    TTF_RenderText_Solid() outputs 8-bit palettized surfaces,而不是 TextSprite::createTexture() 操作的 32 位 ARGB 表面。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-24
      • 2015-03-25
      • 2013-05-15
      相关资源
      最近更新 更多