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
"I never really thought that creating your initial game loop is this easy! Why did I think I wasn't going to be able to understand this? Looking forward now to start the course I actually bought, if the quality is the same it's going to be great. I like how the videos were straight to the point, but explain some of the background when context might be more important."
23 Jul 2022
"Fabulous course! Very well structured course, just right level of difficulty without getting overwhelmed. It clarified the concept of delta time and game loop very succinctly. I thought as a game developer who has shipped 1-2 small games I understood these ideas before the course but there were nagging gaps that this course helped fill. I also like the how the instructor wrote all the code in front of us line by line. So this was not that 'How to Draw the Owl' kind of a course (if you've seen that joke ;-P )."
16 Jul 2022
Michael Dick
Michael Dick
Computer Science & Math student
"Great for Low Level Understanding! If you're an individual that wants to know everything about low-level computing, or anything that deals with graphics, games, etc, then try this course. The breadth of material and applications of what we do here is absolutely amazing."
14 Jul 2022
Nitin Deshpande
Nitin Deshpande
"Simply great! Mr Pezzi is an amazing teacher. I thoroughly enjoyed the course. The fundamentals are very well explained."
21 Jun 2022
Jean-Jacques Strydom
Jean-Jacques Strydom
"Fantastic course! Really well taught and well explained."
08 Jun 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++.