SDL
Modified 2023-03-31
Installation
Setting up the Makefile
Use pkg-config to properly link to the corresponding library binaries.
build:
g++ `pkg-config --cflags sdl2` -Wall -std=c++17 -I"./libs" src/* `pkg-config --libs sdl2` -llua -o gameengine
run:
./gameengine
clean:
rm gameengine
NixOS
I'm using NixOS, so it's pretty easy to setup the development environment using direnv and a shell.nix.
The shellHook sets up the compile_commands.json file when running it through make.
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
mkShell {
name = "Simple 2D Engine - Shell";
packages = [
# used as a language server
clang
clang-tools
# used to generate compile_commands.json
bear
# used to link the SDL2 sub dependencies
pkgconfig
# project dependencies to trigger autocompletion
lua5_3_compat
SDL2
SDL2_ttf
SDL2_mixer
SDL2_image
];
shellHook = ''
bear -- make
'';
}MacOS
Every MacOS already comes with gcc in the form of a clang alias, so we only
need to brew install sdl2.
Windows
- Install Visual Studio Community Edition
- Desktop development with C++
- Create an empty project
- Add a
main.cto Source Files
- Add a
- Install SDL development library
- Extract the SDL zip
- Add the
includefolder to Include Directories - Add the
libfolder to Library Directories
- Setup the Linker configuration
- Add the
libfolder to Additional Library Directories - Add
SDL2.libandSDL2main.libto the Input dependencies
- Add the
- Add the
SDL2.dllin the project folder - Add a
mainand don't forget the proper arguments required by Windows
#include <SDL2/SDL.h>
#include <stdio.h>
int main(int argc, char* args[]) {
SDL_Init(SDL_INIT_EVERYTHING);
printf("Hello World!");
return 0;
}