Managed DirectX 2.0 VertexBuffer in C++

Started by
2 comments, last by Thorgrim 18 years, 1 month ago
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
Advertisement
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

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.
Great, thanks a lot guys, that was very helpful :)

This topic is closed to new replies.

Advertisement