TexGen coords not clamped

For projective texture mapping I’m computing the projection matrix M = TSP*V-1 where T is the translation by 0.5 in x, y, z, S is scaling by 0.5 in x, y, z, P is the projection with fov = 45, aspect 1.0, near .1, far 1. and V-1 is the inverse of the projector’s transformation. Then I enable GL_EYE_LINEAR and fill the four rows of M into the four texgen planes accordingly.
Now having texture parameters (of the texture to be projected) set to GL_REPEAT the projection is fine and of course repeated. Changing it to GL_CLAMP gives the projected texture but the four borders are then still repeated! The multiplication by P should transform the vector into the range [-1, 1] and the scaling/translating will map to the range [0, 1]. What can be the reason for this repeatness?


IMO, 3 possibilities :

  • the clamp instruction fails, eg you call for GL_CLAMP at a bad moment or with a bad syntax,
  • the drivers sux0rs,
  • something else…

+1 possibility

  • You set wrap mode for wrong texture. Wrap mode is set per texture, and the default wrap mode is repeat.

Sounds like you’re getting the correct behavior. What were you expecting GL_CLAMP to do? OpenGL only clamps the coordinates - but by the spec it still textures every fragment with a positive q. In every implementation I know of it textures fragments with negative q as well.

Thanks -

Bob, the texparams are set correctly.
Cass, then I can set a small (1 or 2 pixel) black boarder around the texture and the “repeated” part would be just black color and not something weird?


cass: I think the correct behaviour would be to clamp texture coordinates in the range [0,1]. If this is the case, why is the texture repeated ? IMO, the fact that coordinates are automatically generated does not skip the clamp operation.

[This message has been edited by vincoof (edited 02-05-2002).]


You could do that or use GL_CLAMP_TO_BORDER.


Clamping is done per-fragment, so it comes after texgen. Kon said the “borders are then still repeated”. This sounds to me like the filtered color half way between the border and edge texels is being smeared - which is the effect of GL_CLAMP.

Thanks -

Ok cass, I missed that detail ! o_O
Sorry. I didn’t see he was talking about repeating the border.

anyhow, I agree with you on your analysis about the GL_CLAMP/border repetition thingy.
But I’d rather choose GL_CLAMP_TO_EDGE, wouldn’t you ?

[This message has been edited by vincoof (edited 02-05-2002).]

Thanks Cass! Using GL_CLAMP_TO_BORDER_ARB gives the expected results. Unfortunately this extension is supported only on GeForce3 (and higher). Having a border of one texel the projected texture looks fine too.
And, CL_CLAMP_TO_EDGE doesn’t solve this problem.


[This message has been edited by kon (edited 02-05-2002).]