commit 256781587be161401568159c37ca5af0d2947dcf Author: Josh Lyon Date: Tue Aug 12 00:22:40 2025 -0600 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba15c89 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +build +compile_commands.json +.cache diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..44c13b1 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.15) +project(sdl-test + LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 26) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$") + +add_subdirectory(deps EXCLUDE_FROM_ALL) + +set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) + +add_subdirectory(src) + diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt new file mode 100644 index 0000000..54060e8 --- /dev/null +++ b/deps/CMakeLists.txt @@ -0,0 +1 @@ +include(${CMAKE_CURRENT_SOURCE_DIR}/fetch_sdl.cmake) diff --git a/deps/fetch_sdl.cmake b/deps/fetch_sdl.cmake new file mode 100644 index 0000000..fbd85c7 --- /dev/null +++ b/deps/fetch_sdl.cmake @@ -0,0 +1,9 @@ +include(FetchContent) +FetchContent_Declare(SDL + GIT_REPOSITORY https://github.com/libsdl-org/SDL.git + GIT_TAG release-3.2.20 + GIT_SHALLOW ON + EXCLUDE_FROM_ALL + SYSTEM) + + FetchContent_MakeAvailable(SDL) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..72d8b9f --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(${PROJECT_NAME} main.cpp) + +target_include_directories(${PROJECT_NAME} PRIVATE ${INCLUDE_DIR}) + +target_link_libraries(${PROJECT_NAME} PRIVATE SDL3::SDL3) + diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..2cf8aa8 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,69 @@ +/* + Copyright (C) 1997-2025 Sam Lantinga + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely. +*/ +#include +#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ +#include +#include + +static SDL_Window *window = nullptr; +static SDL_Renderer *renderer = nullptr; + +/* This function runs once at startup. */ +SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) +{ + /* Create the window */ + if (!SDL_CreateWindowAndRenderer("Hello World", 800, 600, SDL_WINDOW_FULLSCREEN, &window, &renderer)) { + SDL_Log("Couldn't create window and renderer: %s", SDL_GetError()); + return SDL_APP_FAILURE; + } + return SDL_APP_CONTINUE; +} + +/* This function runs when a new event (mouse input, keypresses, etc) occurs. */ +SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) +{ + if (event->type == SDL_EVENT_KEY_DOWN || + event->type == SDL_EVENT_QUIT) { + return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */ + } + return SDL_APP_CONTINUE; +} + +/* This function runs once per frame, and is the heart of the program. */ +SDL_AppResult SDL_AppIterate(void *appstate) +{ + std::string message("Hello World!"); + int w = 0, h = 0; + float x, y; + const float scale = 4.0f; + + /* Center the message and scale it up */ + SDL_GetRenderOutputSize(renderer, &w, &h); + SDL_SetRenderScale(renderer, scale, scale); + x = ((w / scale) - SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE * message.length()) / 2; + y = ((h / scale) - SDL_DEBUG_TEXT_FONT_CHARACTER_SIZE) / 2; + + /* Draw the message */ + SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); + SDL_RenderClear(renderer); + SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); + SDL_RenderDebugText(renderer, x, y, message.c_str()); + SDL_RenderPresent(renderer); + + return SDL_APP_CONTINUE; +} + +/* This function runs once at shutdown. */ +void SDL_AppQuit(void *appstate, SDL_AppResult result) +{ +} +