Programming$/Game Programming C++

SDL_TTF 사용하기

ch4rli3kop 2020. 7. 9. 01:10
반응형

SDL_TTF

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);
}



반응형