im目前在使用SDL_TTF和OpenGL呈现文本时遇到了一个奇怪的错误。
问题是,当我使用TTF_RenderText_Blended时,所有文本都显示得很好,没有任何问题。

但是,当我想要切换到TTF_RenderText_Solid时,会显示“But”黑色矩形,并且我不知道在从表面创建正确的纹理时,是否指定SDL_TTF或OpenGL的问题。

函数从textInfo加载曲面(字体、大小)
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);}
函数从OpenGL创建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);}
谢谢你帮忙。
发布于 2016-12-02 16:05:54
outputs 8-bit palettized surfaces,而不是TextSprite::createTexture()操作的32位ARGB曲面.
https://stackoverflow.com/questions/40936228
复制相似问题