Results 1 to 2 of 2

Thread: push and pop matrix

  1. #1
    Member Newbie
    Join Date
    Mar 2005

    push and pop matrix

    hello i want to rotate the texture matrix and the codes are like this follow:
    i want to know whether the glPushMatirx[]and glPopMatrix[] are useful in this accation?thank you very much!!

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jan 2004

    Re: push and pop matrix

    Good question.

    W.r.t. the code you posted:
    1. Your code also does a loadidentity between the push and the pop. This is only necessary if you want to use a non-identity matrix as the default.
    2. You seem to pop the matrix before you render anything. Don't pop the matrix until you've actually rendered something or you'll see no difference.

    W.r.t. the general question:

    My guess is no.

    The matrix stack is not of infinite depth (the mininum I believe is just one), so don't nest those push/pop pairs.

    My guess is that a glLoadIdentity would be optimised, and since the identity matrix is the default, you would not need a push/pop pair to restore it.
    And my guess is that one glLoadIdentity is at least as fast as a push, and a pop combined.

    But I'm just guessing here.

    My suggestion:

    1. When activating a texture: do the scales, translates and rotates you need. Don't do the glLoadIdentity, since the default state is an identity matrix. Nothing to rotate etc: just skip this part.
    2. render the geometry
    3. When deactivating the texture, if it has modified the texture matrix (you can keep track of this with some booleans), do a glLoadIdentity
    4. go to step 1

    This limits the loadidentities to the bare minimum - only when resetting the matrix to the default. But you have to do it consistently or your textures go crazy.

Similar Threads

  1. Push Pop Matrix troubles
    By gummby8 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 10-26-2016, 04:01 PM
  2. Remembering coordinates (Push/Pop Matrix ?)
    By janemba in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-16-2013, 02:08 AM
  3. Push and Pop Matrix Operations
    By Septimra in forum OpenGL: General
    Replies: 6
    Last Post: 03-06-2011, 05:36 PM
  4. I am using push/pop matrix and I appear to have a memory leak.
    By John Jenkins in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 10-24-2002, 07:39 AM
  5. Push Pop matrix VS Load identity??
    By LostInTheWoods in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 08-01-2002, 02:35 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