简体   繁体   中英

OpenGL ES 2.0 texture clamping

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!

GL_TEXTURE_WRAP_SGL_TEXTURE_WRAP_T设置为GL_REPEAT要求您的纹理尺寸为 2 的幂。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM