Trunk Draw

Apr 24, 2010 at 1:18 PM
Edited Apr 24, 2010 at 1:20 PM

Hello there,

For my study we have the task to make a game in 3D, using C# and XNA.
We found this tool and used it, but we had some problems when using it.

Drawing one tree isn't a problem, just using drawTrunk and drawLeaves.
But if we want to draw more trees (like a forest), we need two while-loops (or forloops) to get the right result.
First one for the Trunks, the second for the Leaves.
If we don't do it this way, and we (for example) draw 10 trees, we only get the first trunk, and the leaves of all 10 trees.
With the two loops all the trunks are drawn.

I made a method to draw a forest (with the two forloops), but when I want to draw a second forest, only the leaves will be drawn, no trunk.

if we also use drawBonesAsLines in the code, we don't need forloops and there is no problems with drawing all the trunks..
but we don't want the lines in the game (because it doesn't look nice)

how can we solve this problem??



Apr 24, 2010 at 2:02 PM

Hello Applepie,

It sounds like a render state issue. The draw calls will mess up the render state and it will not restore it - you have to work in some render state management yourself. This is also stated in the user manual (in bold text). I realize this probably seems annoying when getting started, but it is like this for a reason.

Secondly, you typically want to draw the solid geometry in your scene before the transparent geometry, so using two loops is actually not a bad idea. Of course, you should take care of the render state issue nonetheless.

Good luck with your project!