# Why is it possible to encounter a texture coordinate greater than 1 or less than 0

I'm studying a text about texture mapping and in the preparing to draw session, I read:

Define the texture wrapping parameters. This will control what happens when a texture coordinate greater than 1.0 or less than 0.0 is encountered:

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,wrap);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,wrap);


where wrap is:
GL_REPEAT : specifies that this pattern will repeat (i.e., wrap-around) if transformed texture coordinates less than 0.0 or greater than 1.0 are encountered.

GL_CLAMP : specifies that the pattern will “stick” to the value at 0.0 or 1.0.

But there's no explanation what is the reason of encountering such texture coordinates?
For example suppose that I have just drawen a rectangle and I want to apply an image as a texture on it, is it possible to encounter such coordinates?

Not all textures use texture coordinates that come from the mesh data. For example, with projective texturing, you transform the world into the space of the texture. Well, a lot of that world falls outside the [0, 1] range of the texture. Without some sort of clamping mode in place, you're going to get problems.

Precisely, to repeat a texture.

So, if you have a quad, and the texture coordinates go from 0 to 1, the texture will be drawn once. If the coordinates go from 0 to 2 and wrap is set to GL_REPEAT, then the texture will be drawn twice.

Try it and see it by yourself

• ok @Panda Pajama so for a code like this: float x0 = 0; // top left corner of image float y0 = 0; float x1 = x0 + ImageWidth; // bottom right corner of image float y1 = y0 + ImageHeight; glBegin(GL_TRIANGLE_STRIP); { glTexCoord2f(0, 1); glVertex2f(x0, y1); glTexCoord2f(0, 0); glVertex2f(x0, y0); glTexCoord2f(1, 1); glVertex2f(x1, y1); glTexCoord2f(1, 0); glVertex2f(x1, y0); } there's no possibility to encounter texture coordinates beyond the interval (0,1)? Aug 24, 2013 at 16:22
• @sepideh: Of course not. You specifically kept your texture coordinates on the range [0, 1]. What you don't understand is that you don't have to; you could have made them anything. Also, don't post a bunch of code in comments. If you want clarification, edit your question. Aug 24, 2013 at 16:25
• ok thanks for your guidance about passing codes to my question. I was searching for a way to format codes in commands but couldn't find!!! So you mean encountering such coordinates is not a run-time possible event. It is just specified by the programmer clearly in order to repeate the texture or not. Aug 24, 2013 at 16:31
• @sepideh What does "not a run-time possible event" mean? It's perfectly fine to change your code in the comment to have glTexCoord2f(0, 2); for example. This has a very specific well-defined meaning in both code and when the program is running. If you see this, the programmer has intentionally done it because it gives the result they want. Aug 24, 2013 at 16:59
• @sepideh Of course. OpenGL uses whatever values you give it. If you give it values in the range 0 to 1, you will never get anything else. Aug 24, 2013 at 17:25

Yes, you can encounter texture coordinates greater than 1.0 and smaller than 0.0.

This depends completely on the model, you loaded. Normally, for each vertex there is position, normal, and texture coordinate stored. In most mesh file formats, the texture coordinate is not restricted to any range.

This is used to repeat a texture. For example, to span a texture four time between a quad of vertices, the texture coordinates would be 0,0, 0,4, 4,0 and 4,4. Without texture wrapping, you would need additional vertices to split the surface into 4 times 4 sub surfaces with each the texture coordinates 0,0, 0,1, 1,0, 1,1. Fewer vertices results in better rendering performance.

Typically, it is not desired that the user notices the edges of a repeated texture. Therefore, repeated textures are tileable in most cases. Than means, the right edge fades seamlessly to the left one and the top edge to the bottom one. This way, the transition is smooth and hopefully not notices by the user.

A more advanced, but related topic is, to cleverly obscure the fact that the same texture was repeated multiple times. For example, blending repeated textures of different size, for example a wall texture and a dirt decal, is a common technique.

• Without texture wrapping, you would need additional vertices to split the surface into 4 times 4 sub surfaces with each the texture coordinates 0,0, 0,1, 1,0, 1,1 That is some real practical explanation! Thanks! Mar 21, 2017 at 13:35