First,
we will load an image using an image loader.
In the template code, there is a helper class CTexture. We can use it load a texture like this:
CTexture
m_texture;
m_texture.Load(filename);- The method Load() will
generate a texture object, bind the texture, and transfer it to the GPU
In
our VBO, we can include texture coordinates as vertex attributes. For example, interleaved attributes:

Recall
the VBO is highly configurable and could include additional vertex
attributes. In the template, the VBO
contains
- Position
- Texture coordinate
- Normal
In
the fragment shader, we will use a sampler to
read texels at different fragment locations.
On the client side, we must indicate which texture unit the sampler will
use. For example:
pMainProgram->SetUniform("sampler0", 0);-
This will instruct the sampler “sampler0” in
the fragment shader to use texture unit 0 (more on this later).
Before
rendering, we must bind the texture to make it active:
m_texture.Bind();
Rendering
occurs with the function
glDrawArrays()
or
one of its variants.