glPush/Pop problems

I have some questions regarding glPush/Pop and I was wondering if anyone could point me to the right direction.I am trying to make a 3D model viewer but It seems my program is quite buggy. Now and then I get this unwanted translations and rotations as well as other annoying little things that mess up the whole thing. I did some research and asked a few people around on the internet but I could not solve my problem in any case. Sometimes it made it better and other times even worse than it was. It seems that I am not using glPush/Pop properly but I cant seem to be finding the error. I’ve read a lot about glPush/Pop,how they work and how to use them. Whenever I am about to do some changes(draw objects etc) in the current Matrix I save it and then restore it. The maximum number of nested Push/Pops I have is I think 3. I do not know if that should cause any problems,just that it would make my program a bit slower. If anybody could please give me some insight on what is the best way to use glPush/Pop it would be much appreciated.

Thanks in advance

for every push, make sure you have a pop
otherwise you get a stack overflow, or underflow

some suggestions for matrix:

  1. the maximum number in matrix stack of different mode is not the same. modelview may be the largest.

  2. as dukey has said, always do your work between ‘glPushMatrix’ and ‘PopMatrix’ pair to avoid overflow and underflow errors.


glPushMatrix();

glMultMatrixf(...);
...

glPopMatrix();

  1. the last matrix you applied acts the first. for example :

glTranslatef(...);
glRotatef(...);

will rotate the model first, translate second;

good luck:)

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.