   Managed DirectX with C++/cli
  Hi, i have the great honor to convert my C++ Project into ***** C++/cli and managed directx but there are some problems. But there is a problem and i cant find the reason.Can you find a mistake in the following code?I just want to display a simple cube.The compiler gives no errors and the program runs but nothing is displayed.//VertexBuffer^ vBuffer;array<CustomVertex::PositionNormalColored>^ vert;static const UInt16 sizeCV = sizeof(CustomVertex::PositionNormalColored);//vert = gcnew array<CustomVertex::PositionNormalColored>(24);vBuffer = gcnew VertexBuffer(device, sizeCV * 24, Usage::WriteOnly, CustomVertex::PositionNormalTextured::Format, Pool::Default);Construct(vert); // writing the verticesvBuffer->Lock(0, sizeCV * 24, Direct3D::LockFlags::None);vBuffer->SetData(vert, 0, LockFlags::None);vBuffer->Unlock();// The Render-Method:device->Clear(ClearFlags::Target|ClearFlags::ZBuffer, Drawing::Color::Black, 1.0f, 0);device->BeginScene();device->VertexFormat = CustomVertex::PositionNormalColored::Format;device->SetStreamSource(0, this->vBuffer, this->sizeCV);for(UInt16 i = 0; i < this->vertices; i = i + 4)device->DrawPrimitives(Direct3D::PrimitiveType::TriangleStrip, i, 2);device->EndScene();device->Present();Thanks![Edited by - vegi on June 16, 2009 7:17:02 AM]
  You're never setting any of the Transformation Matrices.   ;  Oh i forgot to mention that, but they are set correctly.   ;  Your vertex buffer has enough room for only one vertex, yet you try to cram 24 vertices in there.The debug output would warn you about this when you lock the buffer.Also, is the Construct() method supposed to modify the "vert" array? The data and the function cannot see each other since they are in different scopes ("vert" in this function scope, and the method in global scope?).As a side note, it is very inefficient to draw one triangle at a time. The whole point of using buffers is that you can draw more stuff using fewer calls.As an another side note, why are you using managed DX when you can call DX natively with C++?   ;Quote:Original post by Nik02Your vertex buffer has enough room for only one vertex, yet you try to cram 24 vertices in there.The debug output would warn you about this when you lock the buffer.Also, is the Construct() method supposed to modify the "vert" array? The data and the function cannot see each other since they are in different scopes ("vert" in this function scope, and the method in global scope?).As a side note, it is very inefficient to draw one triangle at a time. The whole point of using buffers is that you can draw more stuff using fewer calls.As an another side note, why are you using managed DX when you can call DX natively with C++?Ok i changed the vb-size and the Construct() method has the vert array (it was just a posting mistake of me) But the problem is still actual.What do you mean with the inefficients. How i can make it more efficiently ?Does somebody has a simple c++ MDX sample for me ? I can´t find anything about it.   ;  Are you sure that the "vert" array actually holds correct data after you call Construct()? You can verify this with the debugger.Also, it is important to post actual code instead of an inaccurate approximation of it.The most efficient way to draw a cube is to create all the vertices in one vertex buffer, use an index buffer to construct triangles from them, and render the cube as a triangle list. This allows you to reduce the cube-specific rendering calls to just three - SetStreamSource, SetIndices and DrawIndexedPrimitives - instead of seven that you have now. Remember, the calls itself are much more expensive than the setup and rasterization of 12 triangles, half of which aren't even visible at any given time. Hence, it makes sense to draw as many triangles as you (and the hardware) can, with as few calls as you can.   