Archived

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

glTexGen Question

This topic is 5751 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

Hello! I want to use TexGen to texture my skyplane. I know how to use it to strech a surface over a given region, but however, I don''t know how to make it move (add an offset to the texture coordinates). Is that even possible?

Share this post


Link to post
Share on other sites

  
glTranslatef(0.0f, 0.0f, -5.0f);

glBegin(GL_QUADS);
glTexCoord2f(shift, 1);
glVertex3f(0.0f, 1.0f, 0.0f);
glTexCoord2f(shift, 0);
glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(1+shift, 0);
glVertex3f(1.0f, 0.0f, 0.0f);
glTexCoord2f(1+shift, 1);
glVertex3f(1.0f, 1.0f, 0.0f);
glEnd();

shift -= 0.0001f;
if(shift > 1.0f)
shift = 0.0f;
if(shift < 0.0f)
shift = 1.0f;


initialize float shift to 0.0f and be sure to load indentity before calling this.

Later,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

[if you have a link proposal, email me.]

Share this post


Link to post
Share on other sites
ZE: I don''t think it can work with TexGen. In fact it is, but that means he would need to change the generation equation(s). Not easy.

I''d recommend using the texture matrix :

glMatrixMode(GL_TEXTURE);
glPushMatrix();
glTranslatef( /* set here the translation of the texture */ );
draw_my_texture_object();
glPopMatrix();
glMatrixMode(GL_MODELVIEW); // or maybe GL_PROJECTION depending on you app

Very simple and very flexible IMO.

Share this post


Link to post
Share on other sites
thanx for the answers!
The reason I want to use glTexGen is because that I want to use the same vertex array for drawing the skyplane several times with different textures.
So I guess I have to modifie the texture matrix directly.
so, let''s just say I want the texture to be aligned to the xy plane, having it streched by teh scalars ax/ay and I want to use the offset offx/offy. Would this be the matrix to do that?

ax 0 0 offx
0 ay 0 offy
0 0 0 0
0 0 0 0

?

Share this post


Link to post
Share on other sites
In fact the matrix is :

ax 0 0 offx
0 ay 0 offy
0 0 1 1
0 0 0 1

although you don''t have to care about it, since OpenGL computes it himself when you call glTranslate

Share this post


Link to post
Share on other sites