texture coordinates

Hi, in texture mapping, I usually give texture coordinates between 0 and 1, I saw a lot of programs and examples and this rule is always used… Is it possible to set different coordinates, i mean using world coordinates instead of texture coordinates? f.e.:

this is the correct way to do texture mapping


glBegin(GL_QUADS);
{
glTexCoord3f(0.0,0.0,0.5); glVertex3f(0.0,0.0,0.5);
glTexCoord3f(1.0,0.0,0.5); glVertex3f(1.0,0.0,0.5);
glTexCoord3f(1.0,1.0,0.5); glVertex3f(1.0,1.0,0.5);
glTexCoord3f(0.0,1.0,0.5); glVertex3f(0.0,1.0,0.5);
}
glEnd();

Is it possible to set something like this?:


glTexCoord3f(-1,0.0,0.5); glVertex3f(-1,0.0,0.5);
glTexCoord3f(2.0,0.0,0.5); glVertex3f(2.0,0.0,0.5);
glTexCoord3f(2.0,1.0,0.5); glVertex3f(2.0,1.0,0.5);
glTexCoord3f(-1,1.0,0.5); glVertex3f(-1,1.0,0.5);

maybe setting a color to use if my glTexCoord3f isn’t from 0 to 1…

Yes you can use texture coordinates outside the 0…1 range.

The thing is to tell OpenGL what you want the result of lookups out that range to do. You can set your texture to:

  • repeat (0…2 would tile twice)
  • clamp to edge - which repeats the last texel in the texture
  • clamp which uses a border color.

thanks sqrt[-1]! i’m interested in the last option! what i need to modify in my program?

Simply set the texture property GL_TEXTURE_BORDER_COLOR to the color you want and set the texture wrap s/t to GL_CLAMP (or possibly GL_CLAMP_TO_BORDER)

All this happens through the function glTexParameter (when you have an active texture object bound)
See http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml

what’s the difference between GL_CLAMP_TO_BORDER, and GL_CLAMP?

sqrt[-1] linked directly to the docs. Did you consider reading them?

CatDog

GL_CLAMP_TO_EDGE will clamp to the normal texture color that is specified just inside the [O…1] range.
GL_CLAMP_TO_BORDER will clamp to the outer border color (or the border texel if you have defined them).
GL_CLAMP will clamp to color in-between both border and edge.

What coordinates you use also depends on whether you’re using GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE_ARB.