Jump to content
  • Advertisement
Sign in to follow this  
Schinizer

OpenGL How to make a rolling texture?

This topic is 3311 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 new to openGL and I had been trying to do a rolling texture on a single object. However I had few problems with it. I've been trying this code: //global variable float roll = 0; void renderScene() { ... glMatrixMode(GL_TEXTURE); glTranslatef(roll, 0.0f, 0.0f); glMatrixMode(GL_MODELVIEW); renderTerrain(); renderSky(); renderModels(); ... } void idle() { ... roll+=0.0002f; if(roll > 1) roll = 0; ... } What happens is that the texture is moving, but it accelerates :( All my other texture are moving too, which is not what I want >_> I tried modifiying the texture coordinates too. It works for a plane but for a model, the texture movement speed accelerates too.. Anyone know what am I doing wrong here?

Share this post


Link to post
Share on other sites
Advertisement
The texture will accelerate because you adding larger and larger values roll+=0.0002. You can clamp this value to an abitrary value and then reset roll and start the count again(much like use modulus arithmetic. The fact that all you textures are scrolling is due to the fact that the texture matrix will be applied to all textures use afterward. To prevent this only modify the texture matrix when using the texture you want to scroll and then reset it to the identity matrix for all other non scrolling textures. I hope this helps.

Share this post


Link to post
Share on other sites
Your rolling code seems to be fine, since I guess roll is not the speed but the translation offset.

Your problems both originate from the same source: you don't use the matrix stack.

Imagine the following example:

frame 1
roll = 0.0002 -> textures are translated by 0.0002

frame 2
roll = 0.0004 -> textures are translated by 0.0002 + 0.0004 = 0.0006

frame 3
roll = 0.0006 -> textures are translated by 0.0002 + 0.0004 + 0.0006 = 0.0012

etc.

Now, to solve this, use something similar to that:


//set up your modelview matrix here
renderTerrain();

glMatrixMode(GL_TEXTURE);
glPushMatrix(); //save the current state of the texture matrix
glTranslatef(roll, 0.0f, 0.0f); //change the texture matrix
glMatrixMode(GL_MODELVIEW);

renderSky(); //assuming you only want to roll the sky texture

glMatrixMode(GL_TEXTURE);
glPopMatrix(); //restore the saved texture matrix
glMatrixMode(GL_MODELVIEW);

renderModels();


This will cause the roll offset to be 0.0002, 0.0004, 0.0006 etc. for frames 1, 2, 3, etc.
AND it will only cause the sky texture (or better: all textures between the glPush/PopMatrix() pair) to roll.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!