Setting GL_TEXTURE_WRAP_S
and GL_TEXTURE_WRAP_T
to GL_REPEAT
requires your texture dimensions to be powers of two.
OpenGL ES 2.0 texture clamping
-
12-10-2022 - |
Question
i'm trying to get my texture to be tiled when texture-coordinates go beyond 1.
I have tried this:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT),
How ever, when settings these two lines, all I see is black color, no texture at all!
This works, but doesn't give the repeating effect, which i need:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
Help! I've used already couple of hours to investigate with no results!
Solution
OTHER TIPS
You can convert texture coordinate values greater than one to values in the range 0...1 by discarding the fractional part. Here's some code you can put in your fragment shader, assuming that the texture coordinates are in texture_coord:
texture_coord.x = mod(texture_coord.x,1.0);
texture_coord.y = mod(texture_coord.y,1.0);
gl_FragColor = texture2D(s_texture,texture_coord);
I have tested this in OpenGL ES 2.0 and it works as expected, allowing you to use textures of any size, not just powers of two.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow