I'm not asking about how to map the texture itself. I'm just wondering how I could go about evenly mapping a texture to an object so that it repeats itself instead of stretching to the surface.
Thanks.
I'm not asking about how to map the texture itself. I'm just wondering how I could go about evenly mapping a texture to an object so that it repeats itself instead of stretching to the surface.
Thanks.
If you know you're spawning a quad with width
and height
and you want your texture to spawn its entire height exactly once
and you want the width to truncate/repeat accordingly to preserve the texture aspect ratio
then you want your UV x values to run from 0
to width/height
and your UV y values to run from 0
to 1
This way if width
is twice as large as height
, your texture will tile two times horizontally. And correspondingly for other sizes.
You want to set the wrapping mode:
glTexParameteri(GL_TEXTURE2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
You can also do
GL_CLAMP
GL_REPEAT
GL_MIRRORED_REPEAT
GL_CLAMP_TO_EDGE
GL_CLAMP_TO_BORDR
GL_MIRROR_CLAMP_TO_EDGE
See What does changing GL_TEXTURE_WRAP)_(S/T) do? for more info
First set the wrap mode:
glTexParameteri(GL_TEXTURE2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
Then you just need to make your texture coordinates bigger than 1.
Instead of putting 1, 1, you need to put 2, 2 and it will repeat itself twice. Good luck!