Troubleshooting this TutorialSometimes, 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 using index and vertex buffers. 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 MistakesNone listed yet… |
Frequently Asked QuestionsNone listed yet… |
Hey, you said typically vertex and indices info will be loaded from file, could you go into a little more detail about how this is done?
Thanks.
Well, that's really a big enough topic to have about three whole tutorials on. And in fact, I intend on getting to some that does stuff like that.
But let's start with a brief discussion of how that might work, without going into a ton of detail for the moment. For one, that's exactly what the Model class does when you load a 3D model. The Model class is essentially just a wrapper around the kind of stuff we're doing here, so that you don't need to do it yourself.
But more realistically, you'd do it one of a few ways. The simpler way is to read in data from a plain old file, using standard C# file I/O. The better approach, though, is to make a content pipeline extension to do your loading.
Now, perhaps you're wondering what kind of stuff you might load in from a file. Let me give you an example that pops up in lots of places (so much so, that I'd like to make a tutorial for it at some point in time). Let's say you have a height map that you want to create 3D elevation data for. You would load the image in, and create vertex data for each pixel in the image, then make an index buffer for it, and away you go!
Alternatively, there are lots of ways to generate terrain, so you may not even need to load the data from a file, depending on what you're trying to do with it.
Like I said, there's a lot there, but that's some more insight into the idea, anyway.
There are three points I would like to tackle.
1) Using the way taught by the first tutorial, you can associate multiple colours with one vertex depending on faces, but with an index buffer, it looks like you can only associate one single colour to any given vertex. Is there any workaround that lets you have multiple colours but still use indices?
2) One question: in the tutorial, I have noticed that the constructor for VertexBuffer uses GraphicsDevice as its first argument, while the constructor for IndexBuffer is called with graphics.GraphicsDevice; I have taken a quick look in the documentation, but to no avail. Could you please elaborate on this difference?
3) When compiling, I got a warning that the signature (PrimitiveType, int, int, int, int, int) for DrawIndexedPrimitives is deprecated, and that (PrimitiveType primitiveType, int baseVertex, int startIndex, int primitiveCount) should be used instead; the following resulting code does indeed also work well.
Post preview:
Close preview