Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: How to translate only one texture?

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    12

    How to translate only one texture?

    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.

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: How to translate only one texture?

    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----


  3. #3
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    12

    Re: How to translate only one texture?

    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..

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    12

    Re: How to translate only one texture?

    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?

  5. #5
    Senior Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    356

    Re: How to translate only one texture?

    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.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

  6. #6
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: How to translate only one texture?

    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 );

  7. #7
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    12

    Re: How to translate only one texture?

    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.

  8. #8
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: How to translate only one texture?

    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 ?


  9. #9
    Senior Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    356

    Re: How to translate only one texture?

    Quote Originally Posted by hanek
    ES uses fixed point with functions ending with "f".
    from openGL ES documentation
    glTranslatef(GLfloat x, GLfloat y, GLfloat z);


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

    If three people tell you the same thing, maybe you can try it.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

  10. #10
    Junior Member Newbie
    Join Date
    Feb 2009
    Posts
    12

    Re: How to translate only one texture?

    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.



Page 1 of 2 12 LastLast

Similar Threads

  1. GLM::translate
    By OceanJeff40 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-14-2016, 04:11 PM
  2. Replies: 0
    Last Post: 03-19-2014, 10:11 PM
  3. can i translate
    By 6630 in forum OpenGL: Linux
    Replies: 1
    Last Post: 10-23-2007, 06:52 AM
  4. translate; scale; translate;
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-25-2004, 03:28 AM
  5. Represent Rotate and Translate by one Translate
    By Luin in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-02-2000, 01:54 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean