Sign in to follow this  

Managed DirectX 2.0 VertexBuffer in C++

This topic is 4301 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

Hi, I've been trying to create a vertex buffer in managed DirectX in C++, however am having some issues, since the format seems a little different to the way most of the old C# tutorials do it. Does anyone know a site that has some simple tutorials showing how to set up and render some stuff in MDX 2.0 and C++? Anyway, here is the code: I get the D3DERR_INVALIDCALL error when creating the VertexBuffer.

   device->VertexFormat = 
	   CustomVertex::TransformedColored::Format;


   array<CustomVertex::TransformedColored, 1>^ verts;
   verts->Resize(verts, 3);

   verts[0] = 
	   *(new CustomVertex::TransformedColored(
       float(render->Width / 2), float(render->Height / 4), 0.5f, 1, 
	   Color::Blue.ToArgb()));
   verts[1] = 
	   *(new CustomVertex::TransformedColored(
       float(render->Width * 3 / 4), float(render->Height * 3 / 4), 0.5F, 1, 
	   Color::Green.ToArgb()));
   verts[2] = 
	   *(new CustomVertex::TransformedColored(
       float(render->Width / 4), float(render->Height * 3 / 4), 0.5F, 1, 
	   Color::Red.ToArgb()));

   VertexBuffer^ buf = 
     gcnew VertexBuffer(
	   device, 
       verts->Length, 
	   Usage::None, //Usage::Dynamic | Usage::WriteOnly, 
	   CustomVertex::TransformedColored::Format, 
	   Pool::Default, 
	   gcnew System::EventHandler(this, &Form1::OnVertexBufferCreate)
   );

   GraphicsBuffer^ stm = buf->Lock(0, 0, LockFlags::None);
   //stm->Write(verts);
   buf->Unlock();


The line stm->Write(verts); is commented out because the method supposedly needs an array with Type=unsigned char, dimension=1 So I'm guessing something is wrong with my vertex declaration. A lot was just guesswork, as I cant find any relevant documentation :/ If anyone can tell me the changes needed to get this Vertex buffer set up, or a site that can give some more information it would be much appreciated, Thanks

Share this post


Link to post
Share on other sites
Not an answer as such...

Quote:
Original post by Thorgrim
Does anyone know a site that has some simple tutorials showing how to set up and render some stuff in MDX 2.0 and C++?
MDX 2.0 isn't actually final/finished yet - close, but not quite. As such there isn't much material available for it yet - and most questions are better answered via the beta newsgroups. I've been watching the beta MDX group and it seems reasonably busy with these sorts of questions.

Click here to get details on the beta progam.

Maybe someone will be able to answer this thread for you, but it might be worth (re-)posting it in the beta groups where it should get the right sort of attention.

hth
Jack

Share this post


Link to post
Share on other sites
The MDX2 VerexBuffer constructor wants the size of your buffer in bytes and not the number of vertices it contains. verts->Length is only 3 and to small for the format you have specified.

There is a static CreateGeneric method that takes a vertex type struct and the vertices count.

If you want to write an array of your vertex struct you should use the generic Lock<T> method that will give you a generic GraphicsBuffer object with a Write method that handles this struct type.

Share this post


Link to post
Share on other sites

This topic is 4301 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this