0
votes

i'm completely don't understanding opengl+glut works.... PLEASE explain why he does that? =(

I have simple code

void display()
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glPushMatrix();
            ChessboardSurrogate.Draw(6,8,50, 0,0); // draw chessboard(6x8) in (0,0,0) edge per cell 50
        glPopMatrix();

        glPushMatrix();     
            //glutSolidCube(100);  //!!!!! 
        glPopMatrix();

        glLoadIdentity();       
        gluLookAt(  0.0, 0.0, -testSet::znear*2,
                0.0, 0.0, 0.0,
                0.0, 1.0, 0.0);

        glMultMatrixf(_data->m);   // my transformation matrix

        glutSwapBuffers();
    }

And i get the expected result. screenshot #1

Then I uncomment glutSolidCube(100). In any case, I even do push/pop current matrix, and later override it by identity matrix.... i think that i would see the same result image with cude... BUT! i see THIS screenshot #2 What the..... &*^@#$% Why?

If i add code

        glRotatef(angleX,1.0,0.0,0.0);
        glRotatef(angleY,0.0,1.0,0.0);

before glutSwapBuffers, than I'll see that the chessboard on the spot ..... screenshot #3

1

1 Answers

2
votes

This is probably only half the answer, but why on earth are you setting your matrices AFTER drawing ? What do you expect it to do ?

so :

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();       
    gluLookAt(  0.0, 0.0, -testSet::znear*2,
            0.0, 0.0, 0.0,
            0.0, 1.0, 0.0);

    glMultMatrixf(_data->m);   // my transformation matrix
    glPushMatrix();
        ChessboardSurrogate.Draw(6,8,50, 0,0); // draw chessboard(6x8) in (0,0,0) edge per cell 50
    glPopMatrix();

    glPushMatrix();     
        //glutSolidCube(100);  //!!!!! 
    glPopMatrix();


    glutSwapBuffers();

moreover, always make sure you're setting the right matrix :

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt()...

Lastly, unless your Draw() method changes the modelview matrix, your Push/PopMatrix is useless and should be avoided (for performance and portability reasons since it's deprecated)