Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

WarAmp

glTexGen clarification

This topic is 5192 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I''m attempting to implement my own type of fogging system (Not using hardware fog because of blending issues) so I would like to use a vertex''s distance from the camera as the T texture coordinate. (S coordinate is manually specified) Im currently using the following code: float gls[] = {0.0f, 0.0f, -1.0f, 0.0f}; //-Z axis is into the screen. glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGenfv(GL_T, GL_EYE_PLANE, gls); glEnable(GL_TEXTURE_GEN_T); Now this gives horrible shearing and banding of my texture. What I was wondering is: Is my glTexGen correct for getting distance of vertex to camera? And, do I use glTexCoord2f(S_Coord, 0.0) per vertex, or should I use glTexCoord1f because the T coordinate is automatically generated? Thank you for any advice you may have. Waramp. "Before you insult a man, walk a mile in his shoes. That way, when you do insult him, you''ll be a mile away, and you''ll have his shoes."

Share this post


Link to post
Share on other sites
Advertisement
*bump*

Anyone out there have any experience with glTexGen? I just need the vertex distance from the camera as a tex coord...

Googling only returns the Spec for this function, which I obviously don't understand.

[edited by - waramp on March 7, 2004 1:40:50 PM]

Share this post


Link to post
Share on other sites
Awww geez. No sooner than I bump my post I figured it out.

For future reference: here''s how to use the distance from the camera scaled to [0, 1] as a tex coord using glTexGen:

Note: Replace GL_T and GL_TEXTURE_GEN_T with the tex coord you wish to use. (ie, GL_S, GL_Q, etc)

float gls[] = {ViewDir.x, ViewDir.y, ViewDir.z, -(dot(ViewDir, CamPos))};

glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_T, GL_EYE_PLANE, gls);
glEnable(GL_TEXTURE_GEN_T);

and then:

glMatrixMode(GL_TEXTURE);
glScalef(1.0f, 1.0f / fFarPlaneDistance, 1.0f);

Note: make sure you are scaling the coordinate that you selected with glEnable(GL_TEXTURE_GEN_x)


Hope this helps somebody else in the future.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!