We created the MeshRenderer class, but we still need to load the texture and set the texture ID, which can be passed to the MeshRendered object. For this, we will create a TextureLoader class that will be responsible for loading the textures. Let's see how to do this.
We first need to create the new .h and .cpp file called TextureLoader.
To load the JPEG or PNG image, we will use a header-only library called STB. This can be downloaded from https://github.com/nothings/stb. Clone or download the source from the link and place the stb-master folder in the Dependencies folder.
In the TextureLoader class, add the following:
#include <string> #include <GL/glew.h> class TextureLoader { public: TextureLoader(); GLuint getTextureID(std::string texFileName); ~TextureLoader(); };
We will then use the string and glew...