Results 1 to 2 of 2

Thread: PushMatrix, PopMatrix

  1. #1
    Member Contributor
    Join Date
    Nov 2002
    Location
    Oirsbeek,Holland
    Posts
    69

    PushMatrix, PopMatrix

    Hi, i wrote following source code, it works alomost well, I have the squad before my camera even if i move or rotate the camera. But there is a small problem. If i move camera in way of axe Y, or i rotate it , the quad is moving. If i move the camera on axe Y so just a little bit. Does somebody know how could i make it work ?
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glRotatef(0,1,0,0);
    glRotatef(0,0,1,0);
    glRotatef(0,0,0,1);
    glLoadIdentity();
    glOrtho(0,100,0,133,-10,10);
    glMatrixMode(GL_MODELVIEW);
    glBegin(GL_QUADS);
    glColor3f(1,1,0);
    glVertex3f(0,10,0.1);
    glVertex3f(100,10,0.1);
    glVertex3f(100,0,0.1);
    glVertex3f(0,0,0.1);
    glEnd();
    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

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

    Re: PushMatrix, PopMatrix

    glPush/Pop matrix() between objects:

    glPushMatrix()
    glTranslatef(.....)
    glRotatef(......)
    draw_object();
    glPopMatrix()


    Look at my comments to your program.

    glMatrixMode(GL_PROJECTION);
    glPushMatrix(); // do not use here.
    glRotatef(0,1,0,0); //remove these from the project matrix
    glRotatef(0,0,1,0); //remove
    glRotatef(0,0,0,1); //remove
    glLoadIdentity(); // This voids the past rotate commands, so you glRotate's before do nothing
    glOrtho(0,100,0,133,-10,10);
    glMatrixMode(GL_MODELVIEW);
    glBegin(GL_QUADS);
    glColor3f(1,1,0);
    glVertex3f(0,10,0.1);
    glVertex3f(100,10,0.1);
    glVertex3f(100,0,0.1);
    glVertex3f(0,0,0.1);
    glEnd();
    glMatrixMode(GL_PROJECTION); // remove
    glPopMatrix(); // remove
    glMatrixMode(GL_MODELVIEW); // remove

    [This message has been edited by nexusone (edited 11-26-2002).]

Similar Threads

  1. pushMatrix- PopMatrix
    By AmitGupta in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 02-09-2009, 11:36 AM
  2. glScalef() PushMatrix, PopMatrix()
    By Abacaxi in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-30-2005, 03:28 PM
  3. pushmatrix and popmatrix
    By hoganh in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-27-2003, 11:55 PM
  4. Invariance after PushMatrix/PopMatrix?
    By Tom Nuydens in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 04-14-2003, 05:56 AM
  5. pushmatrix and popmatrix
    By fox in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 09-05-2000, 10:51 AM

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