drawing trees recursively (and rotation)

I’m trying to draw trees recursively, so you start at the trunk and then draw branches that draw branches etc…

I’m trying to use gluCylinder, but I’m having problems keeping track of multiple rotations when I have to draw a branch off of a previous branch. Things get confusing because after a few rotations, glRotate(x, 0, 0, 1) for example won’t necessarily rotate around the Z axis since matrix operations have built up.

Any advice on how to go about this?

You could try and using
glPushMatrix and glPopMatrix. It may help in simplifing the proglem but then again I did really think about the problem long enough to grasp the complexity of the problem.

You have to get familiar with global and local coordinate systems.
For growing trees with L-systems the next branch in the hierarchy will have to inherit the whole transformation of it’s predecessors and add it’s own local transformation on top of that.
Right, glPush- and glPopMatrix is one way. Don’t exceed the GL_MAX_MODELVIEW_STACK_DEPTH!