Add hello world sdl project
The idea is eventually to visualize the tree to help debugging
This commit is contained in:
53
TreeVis.cpp
Normal file
53
TreeVis.cpp
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <SDL.h>
|
||||
#include <SDL_ttf.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
SDL_Init(SDL_INIT_VIDEO);
|
||||
|
||||
TTF_Init();
|
||||
|
||||
SDL_Window *window =
|
||||
SDL_CreateWindow("Hello World", SDL_WINDOWPOS_UNDEFINED,
|
||||
SDL_WINDOWPOS_UNDEFINED | SDL_WINDOW_ALLOW_HIGHDPI, 1920,
|
||||
1080, SDL_WINDOW_SHOWN);
|
||||
|
||||
SDL_Renderer *renderer =
|
||||
SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
|
||||
|
||||
TTF_Font *font =
|
||||
TTF_OpenFont("../third_party/scientifica/ttf/scientifica.ttf", 72);
|
||||
|
||||
bool running = true;
|
||||
while (running) {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event)) {
|
||||
if (event.type == SDL_QUIT) {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
auto *surface = TTF_RenderUTF8_Solid(font, "Hello World", {0, 255, 0});
|
||||
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);
|
||||
SDL_Rect dst = {0, 0, 0, 0};
|
||||
SDL_QueryTexture(texture, NULL, NULL, &dst.w, &dst.h);
|
||||
SDL_RenderCopy(renderer, texture, NULL, &dst);
|
||||
|
||||
SDL_DestroyTexture(texture);
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
TTF_CloseFont(font);
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
TTF_Quit();
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user