From 57a9b20449879efdc2fcaa881038ebfe9bdbec2a Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Thu, 26 Dec 2024 15:34:22 +0000 Subject: [PATCH] Create basic SDL2 application --- CMakeLists.txt | 3 +++ README | 4 ++++ app/CMakeLists.txt | 8 ++++++++ app/main.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 app/CMakeLists.txt create mode 100644 app/main.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a5b240..326baeb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,10 @@ add_custom_target(lint WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} ) +find_package(SDL2 REQUIRED CONFIG REQUIRED COMPONENTS SDL2 SDL2main) + add_subdirectory(engine) +add_subdirectory(app) if (${TESTS}) enable_testing() diff --git a/README b/README index 5f26f43..32c1edc 100644 --- a/README +++ b/README @@ -1,5 +1,9 @@ 2D GAME +Dependencies: + +- SDL2 :: https://www.libsdl.org/ + The build is handled with CMake (version 3.10 or later): cmake -B build diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt new file mode 100644 index 0000000..ab763cb --- /dev/null +++ b/app/CMakeLists.txt @@ -0,0 +1,8 @@ +add_executable(game + main.c +) +set_default_target_options(game) +target_include_directories(game PUBLIC include) + +target_link_libraries(game + PRIVATE SDL2::SDL2 SDL2::SDL2main) diff --git a/app/main.c b/app/main.c new file mode 100644 index 0000000..1afc48b --- /dev/null +++ b/app/main.c @@ -0,0 +1,46 @@ +/* + * Copyright (c) Camden Dixie O'Brien + * SPDX-License-Identifier: AGPL-3.0-only + */ + +#include +#include + +#define TILESIZE 32 +#define WINWIDTH 30 +#define WINHEIGHT 20 + +SDL_Window *window; +SDL_Renderer *renderer; + +int main(void) +{ + int err = SDL_Init(SDL_INIT_VIDEO); + assert(0 == err); + window = SDL_CreateWindow( + "2D Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + TILESIZE * WINWIDTH, TILESIZE * WINHEIGHT, 0); + assert(NULL != window); + renderer = SDL_CreateRenderer(window, -1, 0); + assert(NULL != renderer); + + SDL_Event event; + SDL_RenderClear(renderer); + while (1) { + SDL_PollEvent(&event); + switch (event.type) { + case SDL_QUIT: + goto quit; + + default: + break; + } + } + +quit: + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +}