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

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.

Window Visibility

Learn how to control the visibility of SDL2 windows, including showing, hiding, minimizing, and more
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In this lesson, we’ll continue exploring window management with SDL2, focusing on visibility. We’ll cover:

  • Hiding and showing windows
  • Using always-on-top windows
  • Flashing windows to grab attention
  • Minimising and restoring windows

Mouse Input Constraints

Implement mouse constraints in SDL2 to control cursor movement using window grabs and rectangular bounds
Abstract art representing computer programming
Ryan McCombe
Updated
Published

SDL2 provides tools for controlling mouse movement in our applications. In this lesson, we'll explore how to constrain the mouse cursor to specific windows and regions, giving you precise control over user input. Key topics covered:

  • Window-level mouse grabbing using SDL_WINDOW_MOUSE_GRABBED
  • Dynamic mouse grab toggling with SDL_SetWindowMouseGrab
  • Rectangular constraints using SDL_SetWindowMouseRect
  • Combining grab and rectangle constraints
  • Error handling and state verification

Relative Mouse Mode

Learn how to restrict cursor movement to a window whilst capturing mouse motion continuously.
Abstract art representing computer programming
Ryan McCombe
Updated
Published

So far, our example programs have been using the mouse to control a pointer within our window, letting users point and click on UI elements. However, many programs, especially first-person games, use the mouse differently. For example:

  • Rather than controlling a pointer, the mouse controls the direction that the player’s character is looking.
  • The pointer can never leave the window. For example, the player can move their mouse as far as they want in any direction - our program will continue to react appropriately by, for example, continuously rotating their character.

Implementing an Application Loop

Step-by-step guide on creating the SDL2 application and event loops for interactive games
Abstract art representing computer programming
Ryan McCombe
Updated
Published

The first step of implementing any application is writing the foundational code that keeps the program running until we or the user decide it’s time to quit. This code is often called the application loop, main loop, or, if we’re making a game, the game loop.

Typically, every iteration of the loop involves 3 steps:

  1. Process any events, such as user input. This involves a second, nested loop often called the event loop.
  2. Ask all of our objects to update themselves, ready to be rendered to the screen. Any events that occurred in step 1 can influence this process
  3. Render a new frame to the screen, so the user can see the changes.

Managing Window Input Focus

Learn how to manage and control window input focus in SDL applications, including how to create, detect, and manipulate window focus states.
Abstract art representing computer programming
Ryan McCombe
Updated
Published

On most platforms, multiple applications can be open at once. However, when the user is providing input on their keyboard, they typically only intend to provide that input to one of the open applications.

Users can select which application is active by, for example, clicking within its window.

Operating systems typically apply more vibrant styling to the active window. In the following example, the left window is inactive, while the right is active.

Accordingly, the user will not expect the left window to react to keyboard events, as their input is likely intended for the right window instead:

Managing Mouse Focus with SDL2

Learn how to track and respond to mouse focus events in SDL2, including handling multiple windows and customizing focus-related click behavior.
Abstract art representing computer programming
Ryan McCombe
Updated
Published

In desktop environments, users can have multiple windows open at once. On most platforms, only a single window can have input focus at a time, which is typically gained by the user clicking on the window:

Screenshot showing windows with and without focus

This is referred to as input focus, and we covered it in more detail in our earlier lesson on keyboard input:

In this lesson, we’ll introduce the related concept of mouse focus. A window has mouse focus if the user’s pointer is currently hovering over it. The window with mouse focus is not necessarily the same as the window with input focus.

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