반응형
SDL이용해서 문자를 화면에 나타낼 수 있다.
나는 화면에 스코어 나타내려고 사용했음.
SDL_TTF install
https://www.libsdl.org/projects/SDL_ttf/release/SDL2_ttf-devel-2.0.15-VC.zip
SDL_TTF Usage
https://gigi.nullneuron.net/gigilabs/displaying-text-in-sdl2-with-sdl_ttf/
대충 다음처럼 함수만들어서 사용하면 편함.
void Game::PaintText(char* str, int x, int y) {
SDL_Color color = { 255, 255, 255 };
SDL_Surface * surface = TTF_RenderText_Solid(font, str, color);
SDL_Texture* texture = SDL_CreateTextureFromSurface(mRenderer, surface);
int W = 0, H = 0;
SDL_QueryTexture(texture, NULL, NULL, &W, &H);
SDL_Rect dstrect = { x, y, W, H };
SDL_RenderCopy(mRenderer, texture, NULL, &dstrect);
// free space for surface and texture
SDL_DestroyTexture(texture);
SDL_FreeSurface(surface);
}
반응형
'Programming$ > Game Programming C++' 카테고리의 다른 글
Game Programming in c++ Environment Setting (SDL) (0) | 2020.06.17 |
---|