Jump to content
  • Advertisement
Sign in to follow this  
TheNobleOne

MDX VertexBuffer locking problem

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

help me out here please. I am doing a tutorial with MDX August 2005 refresh. I am using Visual C# Express Beta 2 for my coding. In the tutorial they have me creating an array of vertices. The ide is complaining at run time not compile time when it hits this line. what is going on.
CustomVertex.PositionNormal[] verts = (CustomVertex.PositionNormal[]) vertices.Lock(0,0);


Share this post


Link to post
Share on other sites
Advertisement
Here are the methods that handle the vertexbuffer


protected VertexBuffer CreateVertexBuffer(Device device)
{
VertexBuffer buf = new VertexBuffer(typeof(CustomVertex.TransformedTextured),
100,
device,
0,
CustomVertex.TransformedTextured.Format,
Pool.Default);

PopulateVertexBuffer(buf);

return buf;
}

protected void PopulateVertexBuffer(VertexBuffer vertices)
{
CustomVertex.PositionNormal[] verts =
(CustomVertex.PositionNormal[]) vertices.Lock(0,0);

for (int i = 0; i < 50; i++)
{
float theta = (float)(2 * Math.PI * i) / 49;
verts[2 * i].Position = new Vector3((float)Math.Sin(theta), -1, (float)Math.Cos(theta));
verts[2 * i].Normal = new Vector3((float)Math.Sin(theta), 0, (float)Math.Cos(theta));
verts[2*i+1].Position = new Vector3((float)Math.Sin(theta), 1, (float)Math.Cos(theta));
verts[2*i+1].Normal = new Vector3((float)Math.Sin(theta), 0, (float)Math.Cos(theta));
}

vertices.Unlock();
}



here is the render method which calls the setting up of the vertex buffer


protected void Render()
{
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0F, 0);

device.BeginScene();

// render here
SetupMatrices();
SetupLights();
SetupMaterials();

device.VertexFormat = CustomVertex.PositionNormal.Format;
device.SetStreamSource(0, vertices, 0);
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 98);

device.EndScene();

device.Present();
}

Share this post


Link to post
Share on other sites
You're creating a vertex buffer to hold CustomVertex.TransformedTextured vertices, and then you try to fill it with CustomVertex.PositionNormal ones. Change TransformedTextured to PositionNormal.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!