Create a Game Loop with C and SDL

Course description

This is a super short tutorial on how to write a simple game loop using C and SDL. We'll code a simple C project from scratch and learn how to configuring our C compiler to work with the SDL library.

sdl tutorial

You will learn how to write a minimal game loop, adjust a variable delta-time, and correctly configure a fixed time between frames. The final result will be a skeleton of a small 2D game that can be used as a starting point for more advanced projects.

The tools you'll need

All you really need is a code editor and a C compiler. All the tools we'll use are cross-platform, so you can follow along with either Windows, macOS, or Linux!

c++ game engine platform

Is this course for you?

This course has no formal prerequisites. However, you should already know the basics of coding (if-else, loops, functions) and how to use the Linux command-line.

This short course is a good option for those who want to try my teaching style before enrolling in other courses.
sdl game loop

About the instructor

gustavo pezzi

Gustavo Pezzi is a university lecturer in London, UK. He has won multiple education awards as a teacher and is also the founder of

Gustavo teaches fundamentals of computer science and mathematics; his academic path includes institutions such as Pittsburg State University, City University of London, and University of Oxford.

teaching certification
higher education academy
pgclt teaching certification
bpp university award

Course content

2 hours total length 9 Chapters Last updated July 2021
  • Motivations & Learning Outcomes
  • A Quick Reflection About Game Engines
  • Libraries and Dependencies
  • Environment Setup
  • Installing Libraries on Linux
  • Installing Libraries on macOS
  • Configuring Visual Studio on Windows
  • Picking a Code Editor
  • Compiling our Code with GCC
  • Makefiles
  • Player Movement
  • Quiz: Compilation and Linking
  • Creating an SDL Window
  • Representing Boolean Values in C
  • Polling SDL Key Events
  • Quiz: SDL Events
  • SDL Rendering
  • Rendering a Rectangle/li>
  • Quiz: Rendering
  • Update Function
  • Fixing our Time Step
  • Variable Delta Time
  • Using SDL Delay
  • Quiz: Update and Delta Time
  • Exercise: "Breakout" Game
  • Collision Detection
  • Uncapped Framerate
  • SDL Delay Accuracy
  • What About Determinism?
  • Conclusion
  • Moving Forward

What students are saying

5 star
4 star
3 star
2 star
1 star
Matěj Smetana
Matěj Smetana
"Way better than every YT videos! It was so good I immediately bought the full C++ Game Engine course, I can totaly recommend it."
18 May 2022
Vladislav Osetrov
"Nice course. Concise and consistent."
04 May 2022
Attila Malarik
Technical Designer at sentiomedia
"Just what I needed!"
28 Apr 2022
Victor Brusca
"I loved this course! I found it to be very professional and informative."
13 Apr 2022
Bruno Marcelo Gaio
"Not for beginners. On 'Compiling Our Code With GCC' starts to speak in Greek."
13 Apr 2022

Other similar courses

3D Computer Graphics Programming

35 hours
  • Create a 3D software renderer from scratch using the C programming language.

C++ 2D Game Engine Development

30 hours
  • Learn to make a simple 2D game engine using modern C++, SDL, ECS, and Lua.

Game Physics Engine Programming

35 hours
  • Learn how to create a 2D rigid-body game physics engine from scratch with C++.