Troubleshooting: Drawing Triangles

Troubleshooting this Tutorial

Sometimes, even though you try hard to understand the information in a tutorial, things don't work out quite like you want it to. This page is here to help you resolve any problems you might be having with the tutorial on drawing triangles. The Common Mistakes section describes common problems that people have when doing the things in this tutorial, and how to resolve them. The Frequently Asked Questions section describes questions that people have that aren't related to mistakes, but rather, trying to understand the stuff better or exploring how it can be used.

If your problem or concern isn't addressed here, feel free to add a comment below, so that I know where you're having trouble. I like to keep these pages fairly clean, so I may remove comments that I felt like have been addressed. If I remove your comment and you don't feel like the problem has been fixed, repost the question and we'll take another look at it.

If a tutorial has a mistake in it, I will fix the mistake and reply to the comment with a brief explanation. However, after a couple of weeks I'll likely go back and remove the original comment as well as my reply, because, hopefully, the problem will have been fixed, and it won't be a concern any more.

Common Mistakes

None listed yet…

Frequently Asked Questions

I don't see my triangles. What am I doing wrong?

Not seeing your triangles is a common problem. As mentioned by user Droid, if you follow the tutorial exactly, this shouldn't be a problem, but then, only using the code from this tutorial won't get you a completed game either.

In most cases, triangles disappear because of a graphics technique called backface culling. In any given scene, roughly half of all triangles are facing away from the camera. Since drawing all of those triangles is quite a bit of work, the graphics device typically will remove, or "cull" triangles that are facing away from the camera ("backfaces").

So how can you tell which direction a triangle is facing? When you list a triangle's vertices, you do so in a certain order. From the camera's viewpoint, going from one vertex to the next in this order will either go in a clockwise order or a counterclockwise order. By default XNA will count counterclockwise triangles as backfaces, and cull them out.

For most things, you don't ever see the backfaces, because they are blocked by the object—that is, the backfaces are actually inside of the object. Occasionally, though, this is not the case. So you can do one of three things:

  • 1. Turn the triangle around, so you can see it.
  • 2. Draw two triangles, one facing in each direction.
  • 3. Specify the graphics device's cull mode to cull clockwise triangles instead, or to not cull any triangles.

Add a New Comment
or Sign in as Wikidot user
(will not be published)
- +