Advertisement

L-System... glPopMatrix(). Can use only twice

Started by January 06, 2003 03:25 PM
5 comments, last by asu80 22 years, 1 month ago
Hai there, Now, i'm doing some l-system programming (using turtle interpretation). In lsystem, if u encounter a F in [ , u have to push (glPushMatrix) the matrix to reserve the matrix stack (curent transformations).It's ok when i'm using the glPushMatrix command because u can glPushMatrix as many as u can, but the problem occurs when i'm popping out the stacks (glPopMatrix) more than 2 times. It only popping out the last two stacks (FILO). I wanna pop out all the stack. I'm using nehe tutorial 5 as the basic program. I quess because i'm using glMatrixMode(GL_PROJECTION). How i'm going to fixed this. Any ideas? One more thing, i'm still confuse the usage of glMatrixMode(GL_PROJECTION) & glMatrixMode(GL_MODELVIEW) in ReSizeGLScene in nehe tutorial 5. If you need help to understand lsystem and turtle interpretation. Go to http://pixie.oum.ox.ac.uk/L-Breeder/tutorial.html and http://pixie.oum.ox.ac.uk/L-Breeder/l-systems.html If not, don't bother. [edited by - asu80 on January 6, 2003 4:40:47 PM] [edited by - asu80 on January 6, 2003 4:43:30 PM]
kiss me to kiss u
Are you performing object transforms in the projection matrix? They should go in the modelview matrix. You should, normally, only set the projection matrix once and never touch it again (or when resizing the window to get the projection to match the window).

As for the matrix stack, the projection matrix stack is only required to be at least 2 entries deep. The modelview matrix stack, on the other hand, is required to be at least 32 entries deep.
Advertisement
quote:
Original post by Brother Bob
Are you performing object transforms in the projection matrix? They should go in the modelview matrix. You should, normally, only set the projection matrix once and never touch it again (or when resizing the window to get the projection to match the window).


YES, but just using GL_QUADS to create the square shape like a branch. I''ve done that (just set projection matrix once and never touch it again EVEN in WM_SIZE case). How i''m going to use glMatrixMode(GL_MODELVIEW) instead of using glMatrixMode(GL_PROJECTION) in glPopMatrix(). Should i put it this way glPopMatrix(); or this glMatrixMode(GL_MODELVIEW); glPopMatrix();. Which ones are the correct usage?

quote:

As for the matrix stack, the projection matrix stack is only required to be at least 2 entries deep. The modelview matrix stack, on the other hand, is required to be at least 32 entries deep.

OOOOoo, no wonder



kiss me to kiss u
Just make sure the modelview matrix is the active matrix stack before you reach the point where you need to do all the push and pops. You don''t have to explicitly activate it everytime you need to push or pop.
if you need to reset the co-ordinate system, chuck in a glLoadIdentity(),remember, you can only pop what you have already pushed. if you call pop more times than you have pushed it will have no effect.

The projection matrix is used to convert the world co-ordinates (x,y,z) to screen co-ordinates. The modelview matrix is the one used to transform objects in your scene.

"Very funny, Scotty. Now beam down my clothes."

Twitter: [twitter]CaffinePwrdAl[/twitter]

Website: (Closed for maintainance and god knows what else)

quote:
Original post by Brother Bob
Just make sure the modelview matrix is the active matrix stack before you reach the point where you need to do all the push and pops. You don't have to explicitly activate it everytime you need to push or pop.


How do you make glMatrixMode(GL_MODELVIEW) as the active matrix? I tried many ways but it still using glMatrixMode(GL_PROJECTION)as the active matrix. Below are the snippet program taken from nehe tutorial 5 as my basic program.

    GLvoid ReSizeGLScene(GLsizei width, GLsizei height)	{if (height==0){ height=1;						}glViewport(0,0,width,height);			glMatrixMode(GL_PROJECTION);			glLoadIdentity();				gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);glMatrixMode(GL_MODELVIEW);			glLoadIdentity();}    




[edited by - asu80 on January 7, 2003 12:15:55 AM]
kiss me to kiss u
Advertisement
quote:
Original post by asu80
Original post by Brother Bob
How do you make glMatrixMode(GL_MODELVIEW) as the active matrix?



just by calling glMatrixMode(GL_MODELVIEW) the modelview matrix stack becomes the active matrix stack. just make sure that your last call to glMatrixMode before you do your object transformations is glMatrixMode(GL_MODELVIEW).

GA
Visit our homepage: www.rarebyte.de.stGA

This topic is closed to new replies.

Advertisement