1

GL stack underflow happens at glPopMatrix();

I can't figure out the problem I have.. But I just guess push & pop Matrix...

I know Popping the stack with nothing on it can occur 'stack underflow... but I don't think I got that problem.. please give me an answer!

gl.glMatrixMode(GL10.GL_MODELVIEW);
            gl.glLoadIdentity();
            gl.glPushMatrix();
                gl.glScalef(1f, 1f, 1f);
                gl.glTranslatef(0f, 0f, 0f);

                gl.glMatrixMode(GL10.GL_TEXTURE);
                gl.glLoadIdentity();
                gl.glTranslatef(0.0f, bgScroll1,0.0f);
                background.draw(gl);
            gl.glPopMatrix();  //stack underflow happens at this line
Krupa Patel
  • 3,309
  • 3
  • 23
  • 28

1 Answers1

2

The GL maintains a seprate matrix stack for each matrix type: GL_MODELVIEW, GL_PROJECTION, adn GL_TEXTURE. The push/pop matrix operations always work on the current matrix mode (as all matrix-related GL commands). So your code pushes on the modelview stack, and tries to pop from the texture matrix stack, which probably is empty.

You should set the matrix mode back to GL_MODELVIEW after you modified the texture matrix.

derhass
  • 43,833
  • 2
  • 57
  • 78
  • Or in Model View Matrix mode? – Kyeongsik Jason Kim Aug 23 '14 at 13:10
  • @KyeongsikJasonKim: You you want to push the texture matrix to the stack? I can't know that. From how the code is organized it looks like you want to save the modelview matrix, apply some local transformations for drawing thatr "background", and restore it. So you should push and later pop the modelview matrix. You might also want the modification of the texture matrix to be local to the "background", so you might want to _additionally_ push and pop that one. – derhass Aug 23 '14 at 13:13