0

C#のDirectXに問題があります。線を引きたいです。まず、DrawUserPrimitivesを使用して実行しましたが、すべて問題ありません。しかし、回転やその他のカメラアクションを実行したいので、vertexBufferに切り替えました。そして、私は窓に何も見えません。

平面上にvertexBufferを埋め、頂点を描画するコードの一部があります。

vertexBuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 
   8 * (CurrentPanel.ElementsCount() + 1), m_device, Usage.None,
   CustomVertex.PositionColored.Format, Pool.Default);
CustomVertex.PositionColored[] verts =
   (CustomVertex.PositionColored[])vertexBuffer.Lock(0, 0);
//this function returns array of verts based on given points.
verts = CurrentPanel.GetLines(); 
vertexBuffer.Unlock();
m_device.Clear(ClearFlags.Target, System.Drawing.Color.FromArgb(255, 255, 255).ToArgb(), 1.0f, 0);
m_device.BeginScene(); //m_device is my DirectX.Device
SetupViewport(); //Set all of matrixes...
m_device.SetStreamSource(0, vertexBuffer, 0);
m_device.VertexFormat = CustomVertex.PositionColored.Format;
//m_device.DrawUserPrimitives(PrimitiveType.LineList, CurrentPanel.ElementsCount() * 4, verts); // <- WHEN I USE THIS ALL IS OK
m_device.DrawPrimitives(PrimitiveType.LineList, 0, 4*(CurrentPanel.ElementsCount()+1)); //<-DO NOT WORK
m_device.EndScene();
m_device.Present(); 

このコードはMicrosoftDirectXサンプルに基づいていることを付け加えたいと思います。

4

1 に答える 1

0

頂点をVertexBufferに書き込みませんでした。

という名前の変数を作成し、vertsそれを使用してメソッドから返される配列を参照し、次に参照される配列をからの戻り値にLock置き換えました。しかし、実際にはVertexBufferには何も書き込みませんでした。vertsCurrentPanel.GetLines()

于 2012-06-08T08:04:04.163 に答える