This repository contains examples of using SDL2 for multimedia, gaming, and machine learning development. It serves as a playground for experimenting with C, SDL, and Vulkan for fun and profit.
-
Primary Goal: Apply mathematics to practical software applications while documenting progress. The documentation can be found within the
docs/
directory. -
Secondary Goal: Create educational material that may be useful in various contexts.
-
Tertiary Goal: Have fun and experiment throughout the process.
- All source code is written in pure C.
- Libraries are used only when absolutely necessary.
- Dependencies are kept to a minimum. The primary dependencies are:
- clang
- cmake
- SDL
- Vulkan
The following platforms are recommended for this project:
- EndeavourOS: Recommended for beginners, enthusiasts, and power users. It is a user-friendly Arch-based derivative.
- Arch Linux: Officially supported for adept and experienced users. This is not recommended for beginners.
- Debian: A good alternative to Ubuntu, suitable for various levels of users and use cases.
Ensure you have the following libraries installed on your Arch Linux system:
-
SDL2 and related libraries:
sudo pacman -S sdl2 sdl2_image sdl2_mixer sdl2_ttf
-
CMake for building the project:
sudo pacman -S cmake clang
The project has the following structure:
.
├── build
├── CMakeLists.txt
├── docs
├── examples
├── LICENSE
├── NOTE.md
├── src
├── test
├── README.md
├── precision.c
├── precision.h
├── primitives.c
├── primitives.h
├── vector.c
└── vector.h
6 directories, 10 files
CMakeLists.txt
: The CMake configuration file.docs
: Documentation providing in-depth information, references, and guides.examples
: Isolated/independent examples.src
: The primary source code (currently empty).test
: Tests forsrc
(currently empty).
Note that the directory structure may evolve over time.
-
Clone the repository:
git clone https://github.com/teleprint-me/sdl-examples.git cd sdl-examples
-
Create the build files using CMake:
cmake -B build -DCMAKE_BUILD_TYPE=Debug
-
Build the project:
cmake --build build -j 8
-
Run the executable:
./build/simple
See docs/building.md
for more information.
Here's a simple example named simple.c
:
#include <SDL2/SDL.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
return 1;
}
SDL_Window* window = SDL_CreateWindow(
"SDL Example",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
640,
480,
SDL_WINDOW_SHOWN
);
if (!window) {
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
return 1;
}
SDL_Event e;
int quit = 0;
while (!quit) {
while (SDL_PollEvent(&e) != 0) {
if (e.type == SDL_QUIT) {
quit = 1;
}
}
}
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
This repository and its contents are licensed under the AGPL license. All respective and legally applicable copyrights apply.