PDA

View Full Version : glPush/Pop problems



alex87
04-15-2009, 02:17 PM
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

dukey
04-16-2009, 05:55 AM
for every push, make sure you have a pop
otherwise you get a stack overflow, or underflow

ephtracy
04-17-2009, 11:28 AM
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();


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



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


will rotate the model first, translate second;

good luck:)