SDL Snake Mac OS

broken image


This is a super simple guide to get SDL2 installed and linked into your project so you can get to the fun stuff (game development) quickly. Created with massive amounts of help from Deacon Blues. I'm trying to compile a cmake project on my mac, but it depends on the SDL. I have alreaday read 'LibSDL, CMake and MacOSX Lion', however I couldn't solve this problem. After half an hour of wtf-ing I found the problem in one of the Qt headers in which this will happen # ifdef MACOSXVERSIONMINREQUIRED # undef MACOSXVERSIONMINREQUIRED # endif # define MACOSXVERSIONMINREQUIRED MACOSXVERSION104 So yeah, the MACOSXVERSIONMINREQUIRED macro will be hijacked to 10.4 and then it will be.

Introduction

SDL stands for Simple DirectMedia Layer and provides an abstraction for underlying hardware, such as video, audio and input devices. It runs on all major platforms like Android, iOS, Windows, Linux and MacOS and several ports for consoles like Playstation 4 and Nintendo Switch exist.

Many companies in the industry actually rely on SDL, among them well-known game developer Valve, which are using SDL for their Source Engine or Crytek for their CryEngine.

Setup

I am on the latest version of Mac OS X, 10.14.2, Mojave.

I personally prefer the manual installation from source a lot over either installing a .dmg file or using homebrew.

We are going to install both SDL2 (v. 2.0.9) and SDL Image (v. 2.0.4).

SDL Image makes it easy to load images as SDL surfaces and textures with file formats such as JPG, BMP and PNG.

Head over to the SDL2 download page and download the latest SDL2 version.

Unzip the directory and cd into it. Run the following commands:

Head over to the SDL Image page and download the latest SDL Image version.

Sdl Snake Mac Os X

Sdl

Unzip the directory and cd into it. Run the following commands:

This should do the trick already!

Now let's have a look at a basic running example in SDL 2.

Now when you compile your code with GCC, make sure to link both SDL2 and SDL2 Image:

Sdl Snake Mac Os 11

That's it! Run your executable with ./main and observe a basic Window created with SDL.





broken image