Back to index

Tutorial 1: Introduction to SDL

In RTR, we will be using SDL, specifically SDL2, rather than glut from COSC1186/I3D last semester. SDL will handle creating a window, OpenGL context, keyboard/mouse input and other events. This tutorial will introduce the basics of the SDL API, by the end of which we’ll have some animating points in a 3D environment as shown in the following image.

axes and particles

Use this skeleton code to get started with an empty window.

The current code is missing the main loop. As discussed in the lecture, unlike glut, SDL does not provide a main loop, instead you must write your own. For now, just put the main loop in main. Use the following structure:

  1. Process events such as keyboard/mouse input. The skeleton code provides handleEvents() which returns true if the user wants to exit.
  2. Allow the events to affect the world. This is commonly done in an update/idle function.
  3. Display/draw/render the result of the updates and swap buffers (using the function SDL_GL_SwapWindow(mainWindow)).

Now to test the code:

Now on to the points:

To add some user interaction to the application: