John Conway's Game of Life implemented in C using SDL as a graphics library.
This small project was implemented with the goal of learning to use the SDL library as a reference for future goal projects, as well as doing my first project with cellula automata. It was implemented using only C and SDL, no other external libraries. A few extra features of this project are:
- Cells have simple shaders choices for different looks
- Random Cell density (choosen randomly between 3) and random cell placement each run
- Pause functionality with
space barwhich maintains the hue changes - Hardware Acceleration support (Vulkan prefered, openGL as fallback)
- Wayland (prefered) and X11 support
- Multiple resolutions support
- Window resizing and window fractional scalling support
- Optional hex color value input for custumizable colors
To be able to execute this program correctly you will need the following
- A Linux Operating System
- GCC
- SDL3
- Makefile
- Clone the project reposoritory
git clone git@github.com:Rapcampo/SDL_Game_of_Life.git game_of_life
cd game_of_life- on the root of the repository
makeThis is it, make run can be used for a quick run of the program in a set resolution. make re for recompiling and make fclean for cleaning up objects and program.
If there is an error SDL\SDL3_main.h include not found, make sure SDL is correctly seen by pkg-config and returns something with pkg-config --libs sdl3 && pkg-config --cflags sdl3 as it may not be able to find the location correclty.
A run of the program can have the following format ./life [width] [height] <shader> <hexcolor> where width and height are the requested resolutions, and shader as an optional hue of choice. A custom color choice can be added by using shader number 4, with the input color in the following formats 0xFFFFFF FFFFFF ffffff. CSS style #ffffff is also supported, however, it needs to be \#ffffff or "#ffffff" as comments in shell start with #.
The resolution can be anything between 640x480 all the way up to 3840x2160, as long as the resolution is cleanly divisible by 10.
It is worth noting that resolution passed as an argument is a request and therefore the window generated will depend on your actual usable monitor resolution as a safety measure. The board will still be generated with the requested resolution and downscalled to the window size (or upscalled in the case of increasing window size after running the program).
Shaders have a few options, which can be seen by running ./life without any arguments, which will give you the format and shader options list.
A regular run of the program will give you a few stats of the current run of it. Like so:
Life git:main ❯ life 1080 1920 2 ✹
Game stats
Name: Game of Life
Window size: 1080x1440
Video driver: wayland
Renderer: gpu
Requested resolution: 1080x1920
Shader Option: Purple
Board size: 270x480
Current Generation: 25