Get Started Now

Intro to C++ Programming

Starting from the fundamentals, become a C++ software engineer, step by step.

LATEST UPDATES

Screenshot from Cyberpunk 2077
Module One

Intro to C++ Programming

Starting from the basics, become a C++ software engineer, step by step

Screenshot from Cyberpunk 2077
Screenshot from The Witcher 3: Wild Hunt
Screenshot from Warhammer: Total War
Screenshot from Cyberpunk 2077
Module Two

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects

Screenshot from Cyberpunk 2077
Screenshot from The Witcher 3: Wild Hunt
Screenshot from Warhammer: Total War
Screenshot from Cyberpunk 2077
Coming Soon

SDL and C++ Development

Learn C++ and SDL development by recreating classic retro games

Screenshot from Cyberpunk 2077
Screenshot from The Witcher 3: Wild Hunt
Screenshot from Warhammer: Total War
MOST POPULAR

Adjacent Cells and Bomb Counting

Implement the techniques for detecting nearby bombs and clearing empty cells automatically.
Abstract art representing computer programming
Ryan McCombe
Published

In this part of our Minesweeper tutorial, we'll build upon our previous code by adding the ability to track and display the count of bombs in adjacent cells.

This feature provides players with the information they need to make informed decisions during gameplay.

We’ll also allow cells to be cleared when there are no adjacent bombs, allowing players to clear large sections of the grid automatically.

Adding Bombs to the Minesweeper Grid

Updating the game to to place bombs randomly in the grid and render them when cells are cleared.
Abstract art representing computer programming
Ryan McCombe
Published

In this part of our Minesweeper tutorial, we'll build upon our existing code to add a crucial element of the game: bombs.

We'll implement the ability to place bombs randomly within our grid and reveal them when cells containing bombs are cleared.

We'll start by updating our global configurations to include new variables for bomb-related events and settings. Then, we'll modify our grid and cell classes to handle bomb placement and rendering.

By the end of this section, you'll have a Minesweeper grid where bombs can be placed and revealed, setting the stage for implementing the game's core mechanics in future parts.

Creating the Grid

Building a two-dimensional grid of interactive minesweeper cells
Abstract art representing computer programming
Ryan McCombe
Published

In this lesson, we'll focus on creating the foundational structure for our Minesweeper game. We'll implement the grid system and individual cells, setting the stage for bomb placement and game logic in future lessons.

We'll start by setting up the necessary parameters in our global configuration, then move on to creating the MinesweeperCell and MinesweeperGrid classes.

Finally, we'll implement basic interaction functionality, allowing players to clear cells and prepare our system for future bomb placement.

Engine Overview

An introduction to the generic engine classes we'll use to create the game
Abstract art representing computer programming
Ryan McCombe
Published

In this series, we'll build a fully functional Minesweeper game from scratch, giving you hands-on experience with game development concepts and C++ programming.

We'll separate our project into two main parts:

  1. An "Engine" module containing components that are generally useful across a wide range of projects, not specific to Minesweeper.
  2. A Minesweeper-specific module that builds upon our engine to create the actual game.

For example, we'll create a general Button class in our engine that can be used across various projects. The cells of our Minesweeper grid will then inherit from this Button class, expanding it with Minesweeper-specific logic such as whether the cell contains a bomb and counting the number of bombs in adjacent cells.

Introduction to SDL_Image

Learn to load, manipulate, and save various image formats using SDL_Image.
3D art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we’ll start using the SDL_Image extension we installed earlier. We’ll cover 3 main topics:

  • Initializing and closing SDL_Image
  • Using the IMG_Load() function to load and render a wide variety of image types, rather than being restricted to the basic bitmap (.bmp) format.
  • Using surface blending modes to use transparency and other techniques when blitting
  • Creating image files from our surfaces using IMG_SaveJPG() and IMG_SavePNG()

We’ll be building upon the basic application loop and surface-blitting concepts we covered earlier in the course:

Rendering Text with SDL_ttf

Learn to render and manipulate text in SDL2 applications using the official SDL_ttf extension
3D art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we’ll see how we can render text within our programs. We’ll use the official SDL_ttf extension we installed earlier in the course.

We’ll build upon the concepts we introduced in the previous chapters. Our main.cpp looks like below.

The key thing to note is that we have created a Text class, and instantiated an object from it called TextExample. This object is being asked to Render() onto the window surface every frame:

Text Performance, Fitting and Wrapping

Explore advanced techniques for optimizing and controlling text rendering when using SDL_ttf
3D art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we’ll build on our text rendering capabilities with some new tools:

  • The ability to adjust the rasterizing process to optimize performance when appropriate
  • Dynamically choosing a font size to fit a target pixel size for our rasterized surface
  • Calculating how much text we can fit within a designated space
  • Rendering multi-line text areas using word wrapping, and controlling the alignment of the lines

Our main.cpp is below. Compared to the last lesson, we’ve added a GetWidth() method to the Window class.

Loading and Displaying Images

Learn how to load, display, and optimize image rendering in your applications
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we’ll see how we can load images into SDL, and then display them in our window.

We’ll build upon the concepts we introduced in the previous chapters. Our main.cpp looks like below.

For this lesson, the key thing to note is that we have an Image object called Example, which is being asked to Render() onto the window surface every frame:

// main.cpp
#include <SDL.h>
#include "Image.h" 

class Window {/*...*/}; int main(int argc, char** argv){ SDL_Init(SDL_INIT_VIDEO); Window GameWindow; Image Example; SDL_Event Event; bool shouldQuit{false}; while (!shouldQuit) { while (SDL_PollEvent(&Event)) { GameUI.HandleEvent(Event); if (Event.type == SDL_QUIT) { shouldQuit = true; } } GameWindow.Render(); Example.Render(GameWindow.GetSurface()); GameWindow.Update(); } SDL_Quit(); return 0; }

We’ll build out this Image class across the next two lessons. Our starting point is simply this:

Cropping and Positioning Images

Learn to precisely control image display using source and destination rectangles.
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we'll dive into image positioning and cropping techniques. Here's what we'll cover:

  • Source and Destination Rectangles: Learn how to control which parts of an image are rendered and where they appear on screen.
  • Cropping: Discover how to display only specific portions of an image.
  • Positioning: Learn how to place images precisely where we want them on our destination surface.
  • Clipping: Understand what happens when images don't fit entirely on screen and how to detect it.

As a starting point, we’ll be building upon the basic application loop and surface-blitting concepts we covered in previous lessons:

Image Scaling and Aspect Ratios

Learn techniques for scaling images and working with aspect ratios
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we'll learn how to scale our images up and down during the blitting process. Here's what we'll cover:

  • The SDL_BlitScaled() function, and how it differs from SDL_BlitSurface().
  • What an aspect ratio is, why it matters, and how to calculate it.
  • Using aspect ratios to prevent images being stretched and deformed during scaling.

We’ll be building upon the basic application loop and surface-blitting concepts we covered earlier in the course:

Building a Modular UI System

Learn how to create a flexible and extensible UI system using C++ and SDL, focusing on component hierarchy and polymorphism.
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In the previous section, we introduced the application loop and event loop, which sets the foundation of our program. As our program and interactions get more complex, we need to build additional systems on top of this foundation to help manage the complexity.

In this lesson, we'll dive deeper into managing complex user interfaces by implementing a modular UI system. We'll cover key topics such as:

  1. Creating a UI manager to handle events and rendering
  2. Implementing nested components for better organization
  3. Utilizing inheritance to create reusable UI elements
  4. Using polymorphism for flexible component management

By the end of this lesson, you'll have a solid foundation for building scalable and maintainable UI systems.

Building Interactive Buttons

Explore techniques for building UI components that respond to user input
Abstract art representing computer programming
Ryan McCombe
Updated
Published

Welcome to this lesson on building interactive UI components using SDL in C++. In this tutorial, we'll explore how to create dynamic buttons that respond to user input.

We'll cover topics such as event handling, creating custom button classes, and implementing hover and click behaviors.

Detecting and Managing Errors

Discover techniques for detecting and responding to SDL runtime errors
Abstract art representing computer programming
Ryan McCombe
Published

As with any code, interacting with SDL can sometimes result in errors. For example, let’s imagine we’re trying to create a window that uses Metal, which is Apple’s API for creating high-performance graphics. To do this, we pass the SDL_WINDOW_METAL flag to SDL_CreateWindow():

#include <SDL.h>

int main(int argc, char** argv) {
  SDL_Init(SDL_INIT_VIDEO);
  SDL_Window* Window = SDL_CreateWindow(
    "Hello World",
    SDL_WINDOWPOS_UNDEFINED,
    SDL_WINDOWPOS_UNDEFINED,
    1024, 768,
    SDL_WINDOW_METAL
  );
  
  return 0;
}

If this program is run on a platform that doesn’t support Metal (such as a Windows machine), window creation will fail, and it might not be obvious why that is. In this lesson, we’ll introduce the ways we can detect and cover from errors coming from SDL.

Module One
3D art showing a progammer setting up a development environment

Intro to C++ Programming

Become a software engineer with C++. Starting from the basics, we guide you step by step along the way

Free, unlimited access

This course includes:

  • 57 Lessons
  • Over 200 Quiz Questions
  • 95% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Module Two
A computer programmer

Professional C++

Comprehensive course covering advanced concepts, and how to use them on large-scale projects.

Free, unlimited access

This course includes:

  • 124 Lessons
  • 550+ Code Samples
  • 96% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Coming Soon
sdl2-promo.jpg

Game Dev with SDL2

Learn C++ and SDL development by creating hands on, practical projects inspired by classic retro games

Under Construction
Get Started Now

Intro to C++ Programming

Starting from the fundamentals, become a C++ software engineer, step by step.

Contact|Privacy Policy|Terms of Use
Copyright © 2024 - All Rights Reserved