我正在尝试使用 SDL2 TTF 和 OpenGL 显示文本。一个奇怪的纹理出现在窗口中,它有正确的大小和正确的位置,但你看不到任何字母。
我试过使用 SDL_CreateRGBSurface() 认为它可能是一种更清洁的恢复像素的方法,但它也不起作用。我的表面从不为 NULL,并且总是通过验证测试。
我在 while() 循环之前使用 get_front() 函数,并在使用 glClear(GL_COLOR_BUFFER_BIT) 之后使用其中的 displayMoney() 函数。
SDL、TTF 和 OpenGL 已正确初始化,我已经创建了一个 OpenGL 上下文。这是有问题的代码:
SDL_Surface* get_font()
{
TTF_Font *font;
font = TTF_OpenFont("lib/ariali.ttf", 35);
if (!font) cout << "problem loading font" << endl;
SDL_Color white = {150,200,200};
SDL_Color black = {0,100,0};
SDL_Surface* text = TTF_RenderText_Shaded(font, "MO", white, black);
if (!text) cout << "text not loaded" << endl;
return text;
}
void displayMoney(SDL_Surface* surface)
{
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA …Run Code Online (Sandbox Code Playgroud)