Jump to content
  • Advertisement
Sign in to follow this  
kindfluffysteve

OpenGL texel offset question for specular effects.

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

Is it possible to do something like this in opengl? glTexCoord2f(u,v); what I want to know is if there is a state variable that can be set prior to this maybe like my imaginary function: void setOffset(u_offset,v_offset); that is to say, this: void setOffset(u_offset,v_offset); glTexCoord2f(u,v); is the same as: glTexCoord2f(u+u_offset,v+v_offset); basically, I'm wondering how to do spherically mapped specular effect that is quick.

Share this post


Link to post
Share on other sites
Advertisement
Check out the texture matrix. With it you can do things like:
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(u_offset,v_offset,0.0);
glMatrixMode(GL_MODELVIEW);
glBegin(...);
glTexCoord2f(u,v);
glEnd();

And (u,v) will be translated by (u_offset,v_offset)

Share this post


Link to post
Share on other sites
If you only setting the offset once, i.e. while you draw you object / skybox whatever. Then you could update the texture matrix and translate that way...

glMatrixMode(GL_TEXTURE_MATRIX); // Think that right!!
glPushMatrix();
glTranslatef(XOffset, YOffset, 0.0f);

Draw Object

glPopMatrix();

Hope that help,

Rob :-D

Share this post


Link to post
Share on other sites
..will it not shift the whole object too?

or is that what the pop matrix thing is for? - cause i do a fair bit of matrix manips to render the object where i want it..

that bit about "drawobject" it could be a display list. will this all work nicely.

Share this post


Link to post
Share on other sites
Transformations on the texture matrix only affects texture coordinates (but it affects all of them, if that's a problem.)

Share this post


Link to post
Share on other sites
oh yeah, one last question. will I need to - in order to make everything normal again do:

glPushMatrix();
glTranslatef(XOffset, YOffset, 0.0f);

Draw Object

glTranslatef(-XOffset, -YOffset, -0.0f);

glPopMatrix();


or does PopMatrix at the end do this?

Share this post


Link to post
Share on other sites
glPopMatrix will do it. It works exactly the same way as the other matrix stacks, so:
glPushMatrix() takes a copy of the matrix at the top of the current stack and pushes it onto the stack.
glPopMatrix() removes the topmost matrix of the current stack.

So if you do glPushMatrix and then some transformations, glPopMatrix will remove these transformations

link

Share this post


Link to post
Share on other sites
Just be a tad careful with pushing and popping with the texture matrix stack. Unlike the modelview matrix the texture matrix stack is much smaller (min modelview is 32, min texture is 2). Although I belive many cards actually have a texture matrix stack thats 8 deep (query it!).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!