Animating a texture across a surface in OpenGL

I'm working with the iPhone OpenGLES implementation and I wish to endlessly scroll a texture across a simple surface (two triangles making up a rectangle). This should be straightforward, but it's not something I've done before and I must be missing something. I can rotate the texture fine, but translate does not work at all. Do I have a minor implementation issue or am I doing something fundamentally wrong?

 // move texture
 glMatrixMode(GL_TEXTURE);
 glPushMatrix();
 glLoadIdentity();

    // increment offset - no reset for demo purposes
 wallOffset += 1.0;

    // move the texture - this does not work
 glTranslatef(wallOffset,wallOffset,0.0);

    // rotate the texture - this does work
 //glRotatef(wallOffset, 1.0, 0.0, 0.0);

 glMatrixMode(GL_MODELVIEW);

 glBindTexture(GL_TEXTURE_2D, WallTexture.name);
 glTexCoordPointer(2, GL_FLOAT, 0, coordinates);

 // simple drawing code
 glNormalPointer(GL_FLOAT, 0, normals);
 glVertexPointer(3, GL_FLOAT, 0, vertices);
 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    // push matrix back
 glMatrixMode(GL_TEXTURE);
 glPopMatrix();
 glMatrixMode(GL_MODELVIEW);

You're incrementing your texture offset by 1.0f ; but textures coordinates are considered in the range [0, 1] , so you're not actually changing the texture coordinates (assuming you've enabled some sort of wrapping).

Try changing that increment (try .01f , or maybe something depending on the framerate) and see if it works. If not, then it may have something to do with the texture parameters you've got enabled.

链接地址: http://www.djcxy.com/p/5804.html

上一篇: 用alpha渲染纹理问题

下一篇: 在OpenGL中通过表面动画纹理