PDA

View Full Version : Texture Clamp Confusion



Flotonic
06-10-2013, 05:10 PM
Is there a way to change the range of GL_CLAMP or easily edit the U/V Coordinates? In an OBJ renderer that I am working on, texture clamping seems to be putting up a fuss.

1054

The cube on the left is using the following code. The upper-right part of the image is what it looks like using GL_MIRROR in place of GL_CLAMP, but scaling the object and moving the camera around makes the textures go crazy, so it looks like a square. The bottom-right part of the image is the texture that is mapped to it.


glGenTextures( 1, &GL_texture[loaded_textures] );
glBindTexture( GL_TEXTURE_2D, GL_texture[loaded_textures] );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );

Any idea what I am doing wrong here?

tonyo_au
06-11-2013, 02:52 AM
Try using GL_REPEAT. If the UV values have a maximum difference of 1 (eg -0.5 - 0.5), the image will not repeat, it will just be offset which is what using a UV value of other that 0-1 is implying.

Flotonic
06-11-2013, 10:01 AM
Thank you for your response! Sorry. I meant GL_REPEAT when I said GL_MIRROR in my first post. If only there happened to be a way to "clamp" GL_REPEAT so the texture mapping was always correct and did not go crazy when scaling and/or rotating the object.