I downloaded the project from here http://silverlight.bayprince.com/tutorials.php?tutorial=13 and tried adding a new OBJ file with a few thousand vertices listed.
The classic teapot works but when I tried loading a different model with alot more vertices included, it suddenly throws this primitiveCount error when the DrawPrimitives gets called.
EDIT:
The code includes a class that would read the data from the OBJ file. This will then return a VertexBuffer
object back to the main program. The drawing starts when the Draw event is called.
There are 417936 vertices created from the OBJ file and since I'm using a trianglelist, I divided the vertices by 3 to get the total primitives count.
here's the code for the draw event:
private void DrawingSurface_Draw(object sender, DrawEventArgs e)
{
GraphicsDevice device = GraphicsDeviceManager.Current.GraphicsDevice;
device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, new Microsoft.Xna.Framework.Color(0, 0, 0, 0), 10.0f, 0);
device.RasterizerState = new RasterizerState()
{
CullMode = CullMode.None
};
device.SetVertexBuffer(_vertexBuffer);
foreach (EffectPass pass in _effect.CurrentTechnique.Passes)
{
pass.Apply();
device.SamplerStates[0] = SamplerState.LinearClamp;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, _vertexBuffer.VertexCount / 3);
}
// set camera
_effect.World = Matrix.Identity;
_effect.View = Matrix.CreateLookAt(new Vector3(_x, _y, _z), Vector3.Zero, Vector3.Up);
_effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 2.0f, 1.0f, 100.0f);
// move camera along a circumference
_x = (float)(_radius * Math.Sin(_hAngle * (Math.PI / 180)));
_z = (float)(_radius * Math.Cos(_hAngle * (Math.PI / 180)));
// move camera along a circumference
//_y = (float)(_radius * Math.Cos(_hAngle * (Math.PI / 180)));
e.InvalidateSurface();
}
then the error occurs on the DrawPrimitives.
Any clues about this?
primitiveCount
. just that. it's not much of a clue but this never happens on simple model files like rendering a torus, cube, teapot etc. \$\endgroup\$ – Bahamut Jul 2 '14 at 17:18