Create basic SDL2 application

This commit is contained in:
Camden Dixie O'Brien 2024-12-26 15:34:22 +00:00
parent 12bbdce162
commit 57a9b20449
4 changed files with 61 additions and 0 deletions

View File

@ -29,7 +29,10 @@ add_custom_target(lint
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
) )
find_package(SDL2 REQUIRED CONFIG REQUIRED COMPONENTS SDL2 SDL2main)
add_subdirectory(engine) add_subdirectory(engine)
add_subdirectory(app)
if (${TESTS}) if (${TESTS})
enable_testing() enable_testing()

4
README
View File

@ -1,5 +1,9 @@
2D GAME 2D GAME
Dependencies:
- SDL2 :: https://www.libsdl.org/
The build is handled with CMake (version 3.10 or later): The build is handled with CMake (version 3.10 or later):
cmake -B build cmake -B build

8
app/CMakeLists.txt Normal file
View File

@ -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)

46
app/main.c Normal file
View File

@ -0,0 +1,46 @@
/*
* Copyright (c) Camden Dixie O'Brien
* SPDX-License-Identifier: AGPL-3.0-only
*/
#include <SDL2/SDL.h>
#include <assert.h>
#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;
}