Clamping projective texture coordinates
Hi,
I am trying to make a simple projective texturing demo. I think it works correctly, but the problem is that the texture is wrapping, so it's being tiled across the surface.
So, I tried this:
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
This doesn't really work though, as far as I can tell... Although it does create the desired effect of making only one "tile" of my texture appear, the edges of the texture seem to continue beyond where they are supposed to end.
It's a bit hard to explain, so here's 2 images- the one on the left is uses GL_CLAMP.
EDIT: I also tried setting GL_TEXTURE_BORDER_COLOR to black, but the edges of the texture are still "bleeding".
Thanks a lot!
roos
I think what you need to do is to set a border, and ask GL to use the border color when it's out of range. The specific constant for TexParameter is CLAMP_TO_BORDER, and is only available since GL 1.3. You may need to use CLAMP_TO_BORDER_ARB, depending on how you're loading extensions.
You need to set the clamp mode to GL_CLAMP_TO_BORDER. With GL_CLAMP texture coordinates are clamped halfway between the texture and the border, resulting in your left image.
Edit: Just too late :)
Edit: Just too late :)
Oh man, THANK YOU guys so much, it works fine now! It would've taken me ages to figure that out, because the documentation I was looking at said there was only GL_CLAMP and GL_REPEAT.
roos
roos
Yeah, this stuff is tricky. Since OpenGL's functionality is pretty mediocre in 1.1, a lot of the useful stuff is in extensions, and often times you basically have to know what you're looking for already. Most docs are written to 1.1, and you have to read the extension spec to find the extra constants...but you need to know what extension spec to look at.
Haha yeah, finding good documentation is kind of tricky. I have the OpenGL "Red Book" from college, but it's 1.1, so it's useless...
Anyways, I ran into another problem :/ When I render my projective mapping demo into a texture, the GL_CLAMP_TO_BORDER setting seems to get ignored. Through a bit of trial and error, I figured out that I could "force" it to recognize the setting by calling the following code at the beginning of each scene render:
cgGLEnableTextureParameter( texture );
cgGLDisableTextureParameter( texture );
Also, even when I was rendering the scene normally (not to a texture), it would use GL_REPEAT for the FIRST render, although subsequent frames would render properly. Anyways, my solution is alright as a temporary hack, but if anyone could point out what the proper way to do this is, I'd appreciate it!
Thanks a lot!
roos
[Edited by - roos on May 31, 2005 9:39:52 PM]
Anyways, I ran into another problem :/ When I render my projective mapping demo into a texture, the GL_CLAMP_TO_BORDER setting seems to get ignored. Through a bit of trial and error, I figured out that I could "force" it to recognize the setting by calling the following code at the beginning of each scene render:
cgGLEnableTextureParameter( texture );
cgGLDisableTextureParameter( texture );
Also, even when I was rendering the scene normally (not to a texture), it would use GL_REPEAT for the FIRST render, although subsequent frames would render properly. Anyways, my solution is alright as a temporary hack, but if anyone could point out what the proper way to do this is, I'd appreciate it!
Thanks a lot!
roos
[Edited by - roos on May 31, 2005 9:39:52 PM]
quite a bit of hardware doesnt support clamping to border eg gf2 doesnt
include a recent version of glext.h with your project
u need to set it only once when u create the texture (not every time u use it)
include a recent version of glext.h with your project
u need to set it only once when u create the texture (not every time u use it)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement