Results 1 to 3 of 3

Thread: Why I need pop and push in open gl

  1. #1
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    Why I need pop and push in open gl

    hi every body


    why i need pop and push in open gl

    and when


    best regards

    Moon_Girl
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,068

    Re: Why I need pop and push in open gl

    Think of push/pop as matrix save/load, but works like a stack function.
    Which means that the last item saved will be the first item to be be pulled back off the stack when a pop is called.

    Example I have to objects, both I want to have a 45 degree rotation done on both, but want to do a 5 unit translation on one and a 10 unit translation on the other.

    glRotatef(45, 1.0, 1.0, 1.0);

    glPushMatrix();
    glTranslatef( 5.0, 0.0, 0.0);
    draw_object1();
    glPopMatrix(); // I have restored the matrix back to before the translate was called.

    glPushMatrix();
    glTranslatef(10.0, 0.0,0.0);
    draw_object2();
    glPopMatrix();

    Both objects get a 45 degree rotation, but each one has its own translate. Note you can also rotate and scale inside push/pop.

    If you do not use push/pop matrix placing objects in your 3D world becomes very complicated. Since the next matrix rotations/translations would be ralative to the last ones.

    With push/pop, you can more easly manage your objects.

    glPushMatrix();
    rotate/translate etc.
    Draw_object
    glPopMatrix();

    draw next objects

    For a good example check out my clock program: http://www.angelfire.com/linux/nexusone/index.html


    Originally posted by MOON-GIRL:
    hi every body


    why i need pop and push in open gl

    and when


    best regards

    Moon_Girl


    [This message has been edited by nexusone (edited 12-16-2002).]

  3. #3
    Member Newbie
    Join Date
    Dec 2002
    Posts
    32

    Re: Why I need pop and push in open gl

    thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaank you very much

    i understooood now

    best regards
    Moon_Girl

    [This message has been edited by MOON-GIRL (edited 12-16-2002).]
    SEEK UNDERSTAND and WILL BE UNDERSTOOD

Similar Threads

  1. push and pull
    By Hengasch in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-25-2013, 11:57 AM
  2. Push and Pop Matrixes
    By dvwood in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-30-2008, 09:13 AM
  3. push and pop matrix
    By hwj_just in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-12-2005, 11:53 PM
  4. Replies: 2
    Last Post: 10-10-2003, 10:43 AM
  5. Push/Pop v.s. LoadMatrix?
    By NordFenris in forum OpenGL: Advanced Coding
    Replies: 15
    Last Post: 04-22-2003, 12:19 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