Skip to content

Part 4: SDL

Dmitry V. Sokolov edited this page Feb 17, 2019 · 9 revisions

Step 18: SDL time

It's time to add a graphic user interface. There are a lot of different cross-platform window libraries. Personally, I like imgui, but my students somehow prefer SDL, so I am linking with it. The goal for this step is very simple: create a window and display the image from the previous step:

You can see the modifications here.

Step 19: event handling and cleaning

Event handling is a piece of cake, I won't describe it. After linkage with SDL I have removed the dependency on stb_image.h. STB libraries are stunningly beautiful, but the compile time is abusive.

The source code for the 19th step is the newest code in this repository.

Open in Gitpod

Note how Gitpod is awesome, it allows to run SDL2 games directly in the browser! wasd are used to control the player.

A typical execution of the code looks something like this (click on the image for a youtube video):

TinyRayCaster

Conclusion

As I write this text, the repository contains mere 486 lines of code:

haqreu@daffodil:~/tinyraycaster$ cat *.cpp *.h | wc -l
486

I intentionally did not polish the source code, throwing at you my dirty laundry. Yup, that's what my code looks like (and I'm not the only one). One Saturday morning I just sat down and wrote this :)

I didn't make a completed game, my goal is to give an initial impulse to your fantasy. Write your own code, it will be better than mine for sure. Share your code, share your ideas, send pull requests.