PDA

View Full Version : How to translate only one texture?



hanek
05-07-2009, 02:38 AM
I´ve been playing with OpenGL ES 1.1, and i would like to translate a background texture on a plane mesh.

glTranslate translates every texture after calling it, and i cannot move the drawing code because it has to be in certain order for modelview rotations to have effect on certain meshes.

I´ve been trying to do glPushMatrix() and glPopMatrix() for texture matrix, but no luck.

what is the correct way to do this? Now i have this, which of course translates every texture:

glMatrixMode(GL_TEXTURE);
glTranslatef( 1 << 16 , 0 , 0 );

glMatrixMode(GL_MODELVIEW);
glTexCoordPointer( 2, GL_BYTE, 0, nokTexCoords);
glVertexPointer( 3, GL_BYTE, 0, backgroundVertices);
glBindTexture( GL_TEXTURE_2D, iLoadingTexObjects[2]);
glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, triangles );

----Check if Rotation enabled here----
----Draw the rest of geometry with same kind of code blocks as above----

Thanks in advance.

ZbuffeR
05-07-2009, 03:19 AM
glMatrixMode(GL_TEXTURE);
glPushMatrix();
glTranslatef( 1 << 16 , 0 , 0 );

glMatrixMode(GL_MODELVIEW);
glTexCoordPointer( 2, GL_BYTE, 0, nokTexCoords);
glVertexPointer( 3, GL_BYTE, 0, backgroundVertices);
glBindTexture( GL_TEXTURE_2D, iLoadingTexObjects[2]);
glDrawElements( GL_TRIANGLES, 2 * 3, GL_UNSIGNED_BYTE, triangles );
glMatrixMode(GL_TEXTURE);
glPopMatrix();

glMatrixMode(GL_MODELVIEW); // back to modelview matrix in case the subsequent code assume it.

----Check if Rotation enabled here----
----Draw the rest of geometry with same kind of code blocks as above----

hanek
05-07-2009, 03:44 AM
Thanks, i think i tried everything, just did not get that you have to save the state with pushing the matrix BEFORE calling translate...but now it is making sense when thinking about it..:)

hanek
05-07-2009, 04:33 AM
Actually just now tried the suggested method, but i am not getting any translation on any textures. Is there anything else/more i need to do?

Rosario Leonardi
05-07-2009, 05:41 AM
UV space is from 0 to 1. Beyond these limit texture is repeated (or clamped, or mirrored, you can specify that).
If yoυ translate a non repeating texture by an integer number basically you don't see any change in the final image.

change this
glTranslatef( 1 << 16 , 0 , 0 );
with that
glTranslatef( 0.5f, 0.0f , 0.0f);
to check if your code is working.

ZbuffeR
05-07-2009, 05:42 AM
I don't know ES at all (do you use fixed point ?), but GL texcoords are between 0 and 1.
So translating texcoords by integer value will not change the end result as by default texcoords are looping.
glTranslatef( 1 << 16 , 0 , 0 );

try with :
glTranslatef( 0.2f, 0.1f , 0 );

hanek
05-07-2009, 06:08 AM
ES uses fixed point with functions ending with "f". But the problem is not there now.

If i leave out the bold code in ZBuffer´s example above, all the textures are translating, but if i add the code, nothing is.

I am using opengl es 1.1 plugin with Symbian. It might be that matrix stack has been left out?, just haven´t found anywhere info about this. The specs say that texture matrix stack depth should be at least 2.

dletozeun
05-07-2009, 09:19 AM
If i leave out the bold code in ZBuffer´s example above, all the textures are translating, but if i add the code, nothing is.


That is normal since the matrix is never reset, the translation are "concatenated" at each call.

But the strange thing is that i do not understand why it is working whereas you are translating with an integer. Maybe it is not and I do not know opengl es. What are you intending to do with this: 1 << 16 ?

Rosario Leonardi
05-07-2009, 09:27 AM
ES uses fixed point with functions ending with "f".
from openGL ES documentation
glTranslatef(GLfloat x, GLfloat y, GLfloat z);
:p

f is for float, x for fixed (integer).

If three people tell you the same thing, maybe you can try it. ;)

hanek
05-08-2009, 12:07 AM
Yep, i tried that, just forgot to mention about it. fixed/float confusion was my mistake.

I´ve tried
glTranslatex( 1 << 16 , 0 , 0 ) and
glTranslatef( 0.2f, 0.1f , 0 );

but not working.

Pierre-Luc
05-28-2009, 08:07 PM
Is my answer stupid if I say that since you are pushing and popping the matrix each time, your modifications aren't accumulated.

So every time you pop the matrix, you lose the translation you just did. The next time you do the translation call, you do it on a different matrix. Maybe using a variable that increment with time instead of fixed values should tell you if I'm wrong.

scratt
05-29-2009, 01:09 AM
What you describe seems to make sense to me, but I am not sure of your point.

Although it's not the most efficient way to do it these days, most OpenGL stuff out there tends to push any matrix that is likely to be modified in a sub routine, and then pops it at the end to replace it for the calling function.

That seems to be what you are describing and will indeed work.