Last active
September 15, 2020 23:06
-
-
Save tuket/f31756ba7981df8d625c230a41f19f8e to your computer and use it in GitHub Desktop.
SDL_TTF hello world
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SDL2/SDL.h> | |
#include <SDL2/SDL_ttf.h> | |
const SDL_Color WHITE = { 0xFF, 0xFF, 0xFF, 0 }; | |
int main() | |
{ | |
SDL_Window* window; | |
SDL_Renderer* renderer; | |
SDL_CreateWindowAndRenderer(200, 200, 0, &window, &renderer); | |
TTF_Init(); | |
const char* fontFile = "my_font.ttf"; | |
TTF_Font *font = TTF_OpenFont(fontFile, 32); | |
SDL_Surface* surface = TTF_RenderUTF8_Blended(font, | |
"¡Hellö!", WHITE); | |
SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface); | |
SDL_Rect rect = {10, 10, surface->w, surface->h}; | |
while(1) | |
{ | |
SDL_Event event; | |
SDL_WaitEvent(&event); | |
if(event.type == SDL_QUIT) | |
break; | |
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0); | |
SDL_RenderClear(renderer); | |
SDL_RenderCopy(renderer, texture, 0, &rect); | |
SDL_RenderPresent(renderer); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment