Add hello world sdl project

The idea is eventually to visualize the tree to help debugging
This commit is contained in:
2024-05-08 15:13:58 -07:00
parent 8f7fccee76
commit e2dde59d19
5 changed files with 62 additions and 0 deletions

View File

@@ -74,6 +74,15 @@ set_target_properties(versioned_map PROPERTIES LINKER_LANGUAGE C)
include(CTest) include(CTest)
option(BUILD_TREE_VIS "Build tree visualization" OFF)
if(BUILD_TREE_VIS)
find_package(SDL2 REQUIRED)
find_package(SDL2_ttf REQUIRED)
add_executable(tree_vis TreeVis.cpp)
target_link_libraries(tree_vis PRIVATE SDL2::SDL2)
target_link_libraries(tree_vis PRIVATE SDL2_ttf::SDL2_ttf)
endif()
if(BUILD_TESTING) if(BUILD_TESTING)
add_executable(rootset_test RootSet.cpp) add_executable(rootset_test RootSet.cpp)
target_compile_definitions(rootset_test PRIVATE ENABLE_ROOTSET_TESTS) target_compile_definitions(rootset_test PRIVATE ENABLE_ROOTSET_TESTS)

53
TreeVis.cpp Normal file
View 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;
}

Binary file not shown.

Binary file not shown.

Binary file not shown.