Set Up Your Environment: C++, SDL2, and an AI Assistant

By Carlos Montiel | Enterprise AI Specialist
Leer en español →
Published: 2026-07-28 | By: Carlos Montiel | Reading time: ~4 minutes

Before writing a single line of game code you need an environment that compiles, links, and runs. Let's get it ready in under 30 minutes.

Why SDL2 and Not Something Else

In the previous lesson we talked about what we're going to build. Now it's time to lay the groundwork. We'll use SDL2 (Simple DirectMedia Layer) as our graphics library throughout the course, for three concrete reasons: it's cross-platform (Windows, Linux, macOS), it's low-level — it forces you to understand the game loop, rendering, and input instead of hiding them behind an engine — and it has years of documentation and examples, which helps a lot when your AI assistant needs to give you accurate answers about it.

We won't use an engine like Unity or Godot because the goal of this course is for you to understand the fundamentals of C/C++ applied to games. Once you master this, learning any engine will be trivial.

Installing the Compiler

You need a C++ compiler that supports at least C++17. On Linux, `g++` is the standard choice. On macOS, it's installed along with Xcode's Command Line Tools. On Windows, the simplest option is MSYS2 with `mingw-w64`, or using WSL2 to get a full Linux environment.

# Linux (Debian/Ubuntu) sudo apt update sudo apt install build-essential g++ cmake # macOS xcode-select --install brew install cmake # Windows (inside the MSYS2 MinGW64 shell) pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-cmake

Verify it installed correctly:

g++ --version cmake --version

If you see a version number for both commands, you're ready for the next step.

Installing SDL2

SDL2 can be installed via a package manager on Linux and macOS, and via MSYS2 on Windows. We'll also install `SDL2_image` (for sprites, which we'll use in lesson 4) and `SDL2_ttf` (for on-screen text, useful for the Pong scoreboard).

# Linux (Debian/Ubuntu) sudo apt install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev # macOS (with Homebrew) brew install sdl2 sdl2_image sdl2_ttf # Windows (MSYS2 MinGW64 shell) pacman -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-SDL2_image mingw-w64-x86_64-SDL2_ttf

A First Program to Verify Everything Works

Let's write the "hello world" of SDL2: open a black window and close it with the Escape key or the close button.

// main.cpp #include <SDL2/SDL.h> #include <iostream> int main(int argc, char* argv[]) { if (SDL_Init(SDL_INIT_VIDEO) != 0) { std::cerr << "Error initializing SDL: " << SDL_GetError() << std::endl; return 1; } SDL_Window* window = SDL_CreateWindow( "Environment test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN ); if (!window) { std::cerr << "Error creating window: " << SDL_GetError() << std::endl; SDL_Quit(); return 1; } SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); bool running = true; SDL_Event event; while (running) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) running = false; if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_ESCAPE) running = false; } SDL_SetRenderDrawColor(renderer, 10, 10, 20, 255); SDL_RenderClear(renderer); SDL_RenderPresent(renderer); } SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window); SDL_Quit(); return 0; }

Compile it like this:

g++ main.cpp -o test -lSDL2 ./test

If you see a dark window that closes with Escape, your graphics environment is working.

Setting Up CMake for the Rest of the Course

Starting with the next lesson we'll use CMake so we don't depend on long `g++` commands. This is the skeleton we'll reuse in every subsequent lesson:

# CMakeLists.txt cmake_minimum_required(VERSION 3.16) project(AIGameCourse) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(SDL2 REQUIRED) find_package(SDL2_image REQUIRED) add_executable(game main.cpp) target_link_libraries(game PRIVATE SDL2::SDL2 SDL2::SDL2main SDL2_image::SDL2_image)
mkdir build && cd build cmake .. cmake --build .

Installing and Configuring Your AI Assistant

Now for the other half of the environment: your AI assistant. If you're using Claude Code, install it from the terminal and run it inside your project folder — that way it has full context of your files, your `CMakeLists.txt`, and your compiler errors. If you prefer Cursor, open it directly on the project folder; its AI integration works on the same principle: context from real files, not isolated code fragments pasted into a generic chat.

The key difference of working this way, inside the project, is that you can ask things like "run CMake and tell me why the linker is failing" and the assistant can read the actual error, not one you transcribed halfway. This is especially valuable in C++, where linker errors (undefined symbols, libraries not found) tend to be cryptic for beginners.

// Example of a useful prompt for your assistant while setting up the environment: // "My CMake build fails with 'undefined reference to SDL_Init'. // Here's my CMakeLists.txt and the command I ran. What's missing?"

Recommended Folder Structure

To keep things consistent over the next 11 lessons, use this base structure in every project:

my_game/ ├── CMakeLists.txt ├── src/ │ └── main.cpp ├── assets/ │ ├── sprites/ │ └── sounds/ └── build/

With the compiler, SDL2, and your AI assistant configured and verified, you now have everything you need. In the next lesson we'll use this exact environment to build our first complete game: Pong, step by step, with the main loop, paddles, ball, and scoreboard.

Carlos Montiel
Enterprise AI Solutions Architect
Specialist in LLMs, Agents, and Orchestration
guatemalia.com/en/#contact · info@guatemalia.com

Need to implement AI at your company?

Carlos Montiel is an enterprise AI solutions architect. He implements LLMs, Agents, RAG, and orchestrators for companies across Guatemala and Latin America. Reach out for a consultation.

Contact Carlos Montiel

info@guatemalia.com