SDL_ttf表面与OpenGL纹理通道不匹配

时间:2013-11-24 09:16:05

标签: c opengl colors sdl-2 sdl-ttf

我试图在SDL_ttf表面制作OpenGL纹理,用于游戏中的得分GUI:

SDL_Color scoreColor = { 255, 255, 255, 255 };
SDL_Surface *score = TTF_RenderText_Blended(font, "0 : 0", scoreColor);
SDL_Surface *scoreScaled = SDL_CreateRGBSurface(0, 512, 512, 32, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
SDL_Rect scoreRect = { 0, 0, score->w, score->h };
SDL_Rect scoreScaledRect = { 0, 0, scoreScaled->w, scoreScaled->h };
SDL_BlitScaled(score, &scoreRect, scoreScaled, &scoreScaledRect);
glGenTextures(1, &scoreTextureId);
glBindTexture(GL_TEXTURE_2D, scoreTextureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, scoreScaled->w, scoreScaled->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, scoreScaled->pixels);
SDL_FreeSurface(scoreScaled);
SDL_FreeSurface(score);

但它看起来像红色和alpha通道不匹配: screenshot

我试图使用GL_BGRA和GL_ABGR_EXT而不是GL_RGBA,但它只会导致另一个频道不匹配。

0 个答案:

没有答案