Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Problem whit glPushMatrix and glPopMatrix

Hybrid View

  1. #1
    Newbie Newbie
    Join Date
    Oct 2012
    Posts
    2

    Question Problem whit glPushMatrix and glPopMatrix

    Hi! so I was trying to render basic 2d grid whit some quads today. first I ended up whit code like this:

    Code :
     
    for(int Index = 0; Index < 20; ++Index){
     
     
     
                glTranslatef(0.f,SCREEN_HEIGHT * 0.03f, 0.f);
     
     
     
            for(int Index2 = 0; Index2 < 20; ++Index2){
     
                glTranslatef(SCREEN_WIDTH * 0.03f,0.f, 0.f);
     
                glBegin(GL_QUADS);
     
                    glVertex2f(-10.f,-10.f);
                    glVertex2f(-10.f,10.f);
                    glVertex2f(10.f,10.f);
                    glVertex2f(10.f,-10.f);
     
                glEnd();
     
            }
     
     }
    so that gave me some kind of results: it did render the quads correctly but it changed the line outside the screen, so you coudn't really see the next line of quads.
    so thought I'll just do glPopMatrix and glPushMatrix after and before glTranslatef(0.f,SCREEN_HEIGHT * 0.03f, 0.f);, so i did that and I ran it... and nothing. it gave just black screen. So here's the full code from my render func:
    Code :
       void render()
    {
        //Clear color buffer
     
        glClear( GL_COLOR_BUFFER_BIT );
     
        //Pop default matrix onto current matrix
        glMatrixMode( GL_MODELVIEW );
        glPopMatrix();
        glPushMatrix();
        //Save default matrix again
     
     
        //Move to center of the screen
     
     
       for(int Index = 0; Index < 20; ++Index){
     
           glPopMatrix();
     
                glTranslatef(0.f,SCREEN_HEIGHT * 0.03f, 0.f);
     
           glPushMatrix();
     
            for(int Index2 = 0; Index2 < 20; ++Index2){
     
                glTranslatef(SCREEN_WIDTH * 0.03f,0.f, 0.f);
     
                glBegin(GL_QUADS);
     
                    glVertex2f(-10.f,-10.f);
                    glVertex2f(-10.f,10.f);
                    glVertex2f(10.f,10.f);
                    glVertex2f(10.f,-10.f);
     
                glEnd();
     
            }
     
       }
     
     
     
     
     
    //Update screen
        glutSwapBuffers();
    }
    I'm using freeglut. why is it just giving me a black screen? what am I doing wrong here? thank in advance!

  2. #2
    Newbie Newbie
    Join Date
    Oct 2012
    Posts
    2
    I solved it on my own, I just forgot to use glLoadIdentity()

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •