Hi, let's see a more complex texture mapping. In this demo I have written in the Geometry class a torus rendering method :
void torus(float out_radius, float int_radius, int textureId);
The method takes as input the tube radius ,the big radius from the center of the torus and a texture id. For a good quality rendering is important to set the normal on each vertex of the torus mesh, so for this reason we have the following private method used by torus:
In this post I decided to get some Quake texture and making a simple but interesting 3D scene. As the other OpenGL post, we have a project with some C++ files and classes like Geometry,Scene,Main but in this demo I have used an external class for texture loading, TextureLoader inside the project. The first thing you have to control before to worry about compilation error is the following setting in your Visual C++ project:
Check Character Set = Not Set. Let's see the video demo before to start:
TextureLoader is the class that loads the textures. We have three different textures, one for floor and two for boxes. The initGL() method inside the Scene class has now the code to initialize the textures:
The texture files must reside in your project directory. In my case I made a directory called texture and I put all files here. With Geometry class in the draw() method of the Scene class, we find the code to draw all boxes using textures: