Results 1 to 2 of 2

Thread: Problem whit glPushMatrix and glPopMatrix

  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()

Similar Threads

  1. glPushMatrix() & glPopMatrix()
    By innermostsanctum in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-16-2006, 10:48 AM
  2. glpushmatrix and glpopmatrix
    By jesh in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-18-2003, 05:42 AM
  3. How to use glPushMatrix and glPopMatrix?
    By Structural in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-22-2002, 05:43 AM
  4. glPushMatrix() and glPopMatrix
    By zzapatista in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 02-19-2001, 02:45 AM
  5. glPushMatrix() & glPopMatrix()
    By glbeginner in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 01-07-2001, 10:23 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