2.2 Parameter
If we set our vertices like this:
float size = 0.9f;
vector<Vertex> vertices = {
{ { -size, -size, 0 }, { 0, 0 } },
{ { +size, -size, 0 }, { 1, 0 } },
{ { +size, +size, 0 }, { 1, 1 } },
{ { -size, +size, 0 }, { 0, 1 } },
};
That will give us ths result:
To test the different parameters, let us extent the texture coordinates out of the regular intervall (from 0 to 1):
float size = 0.9f;
vector<Vertex> vertices = {
{ { -size, -size, 0 }, { 0, 0 } },
{ { +size, -size, 0 }, { 2, 0 } },
{ { +size, +size, 0 }, { 2, 2 } },
{ { -size, +size, 0 }, { 0, 2 } },
};
That will give us this result:
You can see that if we try to sample from outside the right / upper edge of the texture, we will get the same color as the last texel that lies within [0:1]. Thats because we used the parameter "GL_CLAMP_TO_EDGE" for both directions the "S" (horizontal) and the "T" (vertical).
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Now lets change one of them, GL_TEXTURE_WRAP_S (horizontal) to another parameter, "GL_REPEAT" for example:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
That will give us this result:
Now we can see that along the "S" direction (horizontally) the texture repeats itself. Let us do the same for the "T" direction (vertically):
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
That will give us this result:
Now we got the same texture twice in both directions, S and T. Let us change again te texture coordinates to:
float size = 0.9f;
vector<Vertex> vertices = {
{ { -size, -size, 0 }, { 0, 0 } },
{ { +size, -size, 0 }, { 5, 0 } },
{ { +size, +size, 0 }, { 5, 2 } },
{ { -size, +size, 0 }, { 0, 2 } },
};
That will give us this result:
Now we have the texture 5x in "S" and 2x in "T" direction. Let us reset the texture coordinates back to:
float size = 0.9f;
vector<Vertex> vertices = {
{ { -size, -size, 0 }, { 0, 0 } },
{ { +size, -size, 0 }, { 1, 0 } },
{ { +size, +size, 0 }, { 1, 1 } },
{ { -size, +size, 0 }, { 0, 1 } },
};
But this time lets interpolate within the texture:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
That will give us this result:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
float size = 0.9f;
vector<Vertex> vertices = {
{ { -size, -size, 0 }, { 0, 0 } },
{ { +size, -size, 0 }, { 5, 0 } },
{ { +size, +size, 0 }, { 5, 5 } },
{ { -size, +size, 0 }, { 0, 5 } },
};
That will give us this result:
XXXXXXXXXXXXXXXXXXXXXXXXXXX
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
That will give us this result: