To Be Continued..
[Concept]
Texture Wrapping
[URL]
http://learnopengl.com/#!Getting-started/Textures
[]
...
Texture coordinates range from0
to1
in thex
andy
axis (remember that we use 2D texture images). Retrieving the texture color using texture coordinates is calledsampling . Texture coordinates start at(0,0)
for the lower left corner of a texture image to(1,1)
for the upper right corner of a texture image. The following image shows how we map texture coordinates to the triangle:
We specify 3 texture coordinate points for the triangle. We want the bottom-left side of the triangle to correspond with the bottom-left side of the texture so we use the(0,0)
texture coordinate for the triangle's bottom-left vertex. The same applies to the bottom-right side with a(1,0)
texture coordinate. The top of the triangle should correspond with the top-center of the texture image so we take(0.5,1.0)
as its texture coordinate. We only have to pass 3 texture coordinates to the vertex shader, which then passes those to the fragment shader that neatly interpolates all the texture coordinates for each fragment.
Texture Wrapping
Texture coordinates usually range from(0,0)
to(1,1)
but what happens if we specify coordinates outside this range? The default behavior of OpenGL is to repeat the texture images (we basically ignore the integer part of the floating point texture coordinate), but there are more options OpenGL offers:
- GL_REPEAT: The default behavior for textures. Repeats the texture image.
- GL_MIRRORED_REPEAT: Same as GL_REPEAT but mirrors the image with each repeat.
- GL_CLAMP_TO_EDGE: Clamps the coordinates between
0
and1
. The result is that higher coordinates become clamped to the edge, resulting in a stretched edge pattern.Each of the options have a different visual output when using texture coordinates outside the default range. Let's see what these look like on a sample texture image:
- GL_CLAMP_TO_BORDER: Coordinates outside the range are now given a user-specified border color.
Each of the aforementioned options can be set per coordinate axis (s
,t
(andr
if you're using 3D textures) equivalent tox
,y
,z
) with thefunction: glTexParameter *
...
[]
...
...
[]
...
[]
...
...
[]
...
[]
...
...
[]
...
[]
No comments:
Post a Comment