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
Capstone Project

Building Minesweeper with C++ and SDL2

Apply what we learned to build an interactive, portfolio-ready capstone project using C++ and the SDL2 library

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

Professional C++

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

Copy Constructors and Operators

Explore advanced techniques for managing object copying and resource allocation
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we’ll explore how objects are copied in more depth. There are two scenarios where our objects get copied. The first is when a new object is created by passing an existing object of the same type to the constructor:

struct Weapon{/*...*/};

int main() {
  Weapon SwordA;
  
  // Create SwordB by copying SwordA
  Weapon SwordB{SwordA};
}

This copying process also happens when we pass an argument by value to a function. The function parameter is created by copying the object provided as the corresponding argument:

struct Weapon{/*...*/};

void SomeFunction(Weapon W) {/*...*/}

int main() {
  Weapon Sword;
  
  // Create the W parameter by copying Sword
  SomeFunction(Sword);
}

The second scenario is when an existing object is provided as the right operand to the = operator. In the following example, we’re expecting an existing PlayerTwo to be updated by copying values from PlayerOne:

struct Weapon{/*...*/};

int main() {
  Weapon SwordA;
  Weapon SwordB;
  
  // Update SwordA by copying values from SwordB
  SwordA = SwordB;
}

As we’ve likely noticed, C++ supports these behaviors by default, even when the objects we’re copying use our custom types. In this lesson, we’ll explore what that default behavior does, and learn how to override it when our classes and structs have more complex requirements.

Video Displays

Learn how to handle multiple monitors in SDL, including creating windows on specific displays.
Abstract art representing computer programming
Ryan McCombe
Published

Modern games and applications often require precise control over display management. In this lesson, you'll learn to retrieve monitor counts, display names, and manage window placement across different displays.

In the context of games, the concepts we cover in this lesson are primarily useful for letting players choose which monitor they want our game to run on:

Window Decorations and Borders

An introduction to managing SDL2 window decorations, borders, and client areas.
Abstract art representing computer programming
Ryan McCombe
Updated
Published

As we likely noticed, platforms typically add additional decorations to our windows, such as a title bar. These decorations include things like title bars and borders. But what if you need a clean, borderless look?

In this lesson, we’ll cover everything you need to know about customizing SDL2 window styles, from removing decorations to dynamically adding them back.

The following screenshot is from Windows 11. It shows a decorated window on the left and an equivalent window without those decorations on the right:

Window Titles

Learn how to set, get, and update window titles dynamically
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we'll explore how to control window titles in SDL2 dynamically. We’ll cover how to set, update, and retrieve titles to provide a polished user experience.

As we’ve seen previously, the first argument to SDL_CreateWindow is a string, representing what we want the title to be. Below, we create a window whose title is "Sample Window":

SDL_CreateWindow(
  "Sample Window",
  100, 100, 700, 300, 0
);

Window Opacity

Discover how to use SDL2 functions for controlling and retrieving window transparency settings.
Abstract art representing computer programming
Ryan McCombe
Updated
Published

On some platforms, we can set the opacity of our window. In this lesson, we explore how to adjust the transparency of SDL2 windows using SDL_SetWindowOpacity() and SDL_GetWindowOpacity(). We’ll cover how to handle errors, retrieve the current opacity, and understand the practical uses of window transparency.

Opacity is represented by a floating-point number ranging from 0.0 to 1.0. The default value is 1.0, which represents a completely opaque window. A window with an opacity of 0.0 is fully transparent.

Intermediate values between 0.0 and 1.0 are used to make our windows semi-transparent. The following window has an opacity of 0.5:

Multiple Windows and Utility Windows

Learn how to manage multiple windows, and practical examples using utility windows.
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we’ll explore how to manage multiple windows using SDL2. We’ll also introduce one of the primary use cases for these techniques, which is creating menus and tooltips.

As we might expect, our program can manage multiple windows by performing multiple invocations to SDL_CreateWindow():

#include <SDL.h>
#include "Window.h"

int main(int argc, char** argv) {
  SDL_Init(SDL_INIT_VIDEO);
  Window GameWindow1;
  Window GameWindow2;
  
  SDL_Event E;
  while (true) {
    while (SDL_PollEvent(&E)) {
      if (E.type == SDL_QUIT) {
        SDL_Quit();
        return 0;
      }
    }

    GameWindow1.Update();
    GameWindow2.Update();
    
    GameWindow1.Render();
    GameWindow2.Render();
  }
}

Our windows do not need to be created at the same time. We can open additional windows in response to user events. Below, our program opens a second window when the user presses their space bar, and closes it when they press escape:

Window Configuration

Explore window creation, configuration, and event handling using SDL's windowing system
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we'll explore SDL's window management system, learning how to create, configure, and respond to window events.

We'll cover essential concepts like window creation, error handling, and event processing, providing the foundation needed to build robust windowed applications.

Window Events and Window IDs

Discover how to monitor and respond to window state changes in SDL applications
Abstract art representing computer programming
Ryan McCombe
Updated
Published

Previously, we’ve seen how we can retrieve aspects of our window’s configuration by checking its window flags. However, we don’t need to continuously monitor our SDL_Window to understand its state.

For most use cases, monitoring the event loop makes more sense. SDL dispatches a wide variety of events reporting actions performed on our window. In this lesson, we’ll explore this in a bit more detail.

Managing Window Position

Learn how to control and monitor the position of SDL windows on screen
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we'll explore SDL's window positioning capabilities, from setting initial window locations to handling dynamic repositioning. We’ll cover

  • How to set window positions explicitly, or use special values that dynamically position our window based on the environment our program is run on
  • Retrieving the current location of our window
  • Moving windows programmatically, including how to shift a window based on its current position
  • Detecting when the user moves our window, so we can respond appropriately
  • A preview of window IDs, which let us manage events in applications that have multiple windows

Window Sizing

Learn how to resize, constrain, and manage SDL2 windows
Abstract art representing computer programming
Ryan McCombe
Updated
Published

This lesson explores the tools SDL2 offers for controlling window sizes and responding to changes. We’ll cover:

  • Allowing users to resize windows.
  • Retrieving and setting window dimensions programmatically.
  • Using resize events for dynamic layouts.
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:

  • 60 Lessons
  • Over 200 Quiz Questions
  • 95% Positive Reviews
  • Regularly Updated
  • Help and FAQ
Capstone Project
3D art representing computer programming

Building Minesweeper with C++ and SDL2

Apply what we learned to build an interactive, portfolio-ready capstone project using C++ and the SDL2 library

Free, unlimited access

This course includes:

  • 37 Lessons
  • 100+ Code Samples
  • 92% 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:

  • 125 Lessons
  • 550+ Code Samples
  • 96% Positive Reviews
  • Regularly Updated
  • Help and FAQ
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