OpenGL | Texture coordinates and wrapping modes

1. Texture coordinate system

In OpenGL, we usually address the pixels in the texture according to the texture coordinates. The texture coordinate system is a spatial rectangular coordinate system. The horizontal axis is the S axis, the vertical axis is the T axis, and the coordinate axis perpendicular to the screen is the R axis. . In our 2D texture, since there is no R axis, we can also call the horizontal axis U and the vertical axis V axis, which is what we call the UV coordinate system.

2. Texture coordinates

In texture mapping, 2D texture coordinates range from [0.0, 1.0]. The lower left corner is (0,0) point and the upper right corner is (1,1) point. When texture coordinates exceed this value, OpenGL handles the situation according to the wrapping mode set.

We can set a wrap mode for each texture coordinate axis (s, t, r) through glTexParameteri. The wrap modes are GL_REPEAT, GL_CLAMP, GL_CLAMP_TO_EDGE, GL_WRAP_TO_BORDER.

  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
  • GL_CLAMP

GL_CLAMP surround mode is clipping over 1.0 to 1.0. The effect is as follows:

  • GL_REPEAT

Wrap patterns are simply repeating textures. For example: the texel at 1.1 is the same as the texel at 0.1. GL_REPEAT is useful when tiled textures are applied to large geometries (such as grass).

Guess you like

Origin blog.csdn.net/weixin_39766005/article/details/129535950