Rendering
We did a lot of work creating our sprites, but nothing is going to show up until we actually render the sprites using OpenGL. Rendering is done for every frame of the game. First, an Update
function is called to update the state of the game, then everything is rendered to the screen.
Adding a render to the game loop
Let's start by adding a call to Render
in the GameLoop
RoboRacer.cpp:
void GameLoop() { Render(); }
At this point, we are simply calling the main Render
function (implemented in the next section). Every object that can be drawn to the screen will also have a Render
method. In this way, the call to render the game will cascade down through every renderable object in the game.
Implementing the main Render function
Now, it is time to implement the main Render
function. Add the following code to RoboRacer.cpp
:
void Render() { glClear(GL_COLOR_BUFFER_BIT); glLoadIdentity(); background->Render(); robot_left->Render(); robot_right->Render(); robot_left_strip...