XNA Essentials

Game Programming for Xbox 360, PC + Windows Phone


DrawRectangle Issue

I'm on Chapter 4 with a problem...

On pg 74, the book discusses making Transformations, as well creating a DrawRectangle method. I got up to pg. 78, where it tells me to put in the "world=Matrix.Identity;" and the "DrawRectangle(ref world);" When I went to compile and run, I got this error:

A valid vertex declaration must be set on the device before any draw operations can be performed.

           *This was attached to the graphics.GraphicsDevice.DrawUserIndexedPrimitives method call code.*

Assuming I did write down everything right, well up to a point, what did I miss, and how do I fix the problem?

AirStyle120 - Thursday, July 1, 2010 @ 4:35 PM

Re: DrawRectangle Issue

Never mind I found the answer:

You left out a piece of code in the book on Chapter 4:

between "effect.CurrentTechnique.Passes[0].Begin();" and "graphics.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertices, 0, vertices.Length,indices, 0, indices.Length / 3);" you left out the line of code that reads

"graphics.GraphicsDevice.VertexDeclaration = vertexDeclaration;"

It wasn't in the book and it gave me the runtime error. After I inserted it, the program ran fine.

AirStyle120 - Thursday, July 1, 2010 @ 6:56 PM