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:

   

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:


   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!

I solved it on my own, I just forgot to use glLoadIdentity() :smiley: