Create a Game Engine: Part V Rendering

In the previous tutorial we set our Scene Manager but unfortunately we didn’t have any models to render. In this part we continue our journey by creating a basic Model class which will be inherited by specific models like Triangle for example. Beside Model, maybe at some point in time we will have Model2 and Model3 required by other types of models which will have different common behaviors. For example Model2 is common for particles or grass and Model3 can be common for ships or cars. To keep these models together and loop over them at the rendering time it’s easier for us if they implement the same interface called IGameObject.

In this part we talk about IGameObject interface and Model class

First we have to create that interface called IGameObject but before that let’s create another folder into our project called Rendering and move VertexFormat.h from Core into this folder. Modify VertexFormat.h by adding a new namespace called Rendering.

This is our basic interface, which must be implemented for all models. I don’t have much to say here, the methods names are pretty clear (I think). GLuint is just a typedef for unsigned int. Draw and Update methods are the most important ones. In Draw we will call the draw methods for the particular model and in Update we update the position or vertices.

Now let’s create the base class called Model which implements this interface and it will be inherited by all models including the triangle. Creating this simple inheritance will also save us from writing duplicate code for other models. We will end up with only two or three methods in our Triangle class.

So first let’s create a new folder called Models inside the Rendering folder and add Model.h and Model.cpp files.

I added a new namespace called Models and implemented the IGameObject interface. As you can see I used some C++11 syntax with theoverride keyword to ensure that we matched the methods from the interface. Now let’s see the cpp code:

In the next part we create the Triangle class based on this IGameObject interface and and Model base class. We also going to look over Models Manager, the place where we handle our triangle and other future models.

I have been working as a software engineer in computer graphics for almost 5 years. In the free time I love playing guitar, playing video games, hiking and studying computer graphics techniques.Follow me on : Google + , Twitter, Facebook