2017-02-25 85 views
0

我在加載SDL_TTF字體時出現問題。 我的代碼:SDL_ttf TTF_OpenFont返回NULL

TTF_Font* font = TTF_OpenFont("Arial.ttf", 24); 
std::cout << "ERROR:" << TTF_GetError() << std::endl; 
SDL_Color color = { 255, 255, 255, 255 }; 

SDL_Rect Message_Rect = { 400,400,100,100 }; 
SDL_Surface* surface = TTF_RenderText_Solid(font, "Text", color); 
SDL_Texture* Message = SDL_CreateTextureFromSurface(Renderer, surface); 
SDL_RenderCopy(Renderer, Message, NULL, &Message_Rect); 

我在Debug文件夾中複製ARIAL.TTF。 TTF_GetError()返回「庫未初始化」。我檢查鏈接器輸入附加的依賴關係。 它包含

SDL2.lib 
SDL2main.lib 
SDL2_image.lib 
SDL2_mixer.lib 
SDL2_ttf.lib 

SDL 2.0.5版本
SDL_image 2.0.1版
SDL_mixer 2.0.1版
SDL_ttf版本2.0.14

我檢查值在調試模式下。之前TTF_OpenFont 0xcccccccc 0x00000000之前

有什麼問題?

回答

1

看起來您尚未初始化SDL TTF。你可以這樣做:

if (TTF_Init() < 0) { 
    // Error handling code 
} 
+0

我添加這個字符串:std :: cout <<「TTF_INIT RETURNS:」<< TTF_Init()<< std :: endl;在控制檯顯示TTF_INIT RETURNS:0 – AceMan

+0

@AceMan您是否在該行之前添加行:'TTF_Font * font = TTF_OpenFont(「Arial.ttf」,24);'? – SurvivalMachine

+0

之前和之後 – AceMan