Skip to main content
gamedev.net
🔒 Locked

glTexGen clarification

Started by WarAmp Mar 6, 2004 at 12:19 PM 1 replies 1k views
Original Post
WarAmp
WarAmp
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."
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.
WarAmp
WarAmp
*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]
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.
WarAmp
WarAmp
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.
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.