差分

ナビゲーションに移動 検索に移動

MonoGame/クラスライブラリ/VertexBufferクラス

1,628 バイト追加, 2017年11月7日 (火) 02:49
編集の要約なし
| (GameResourceクラスから継承)
|}
 
== 実装例 ==
まずVertexBufferを作ってSetDataする。
<source lang="csharp">
// 頂点データを作成する
var vertices = new VertexPositionColor[6];
vertices[0] = new VertexPositionColor(new Vector3(-10, -10, 0), Color.Red);
vertices[1] = new VertexPositionColor(new Vector3(-10, +10, 0), Color.Green);
vertices[2] = new VertexPositionColor(new Vector3(+10, -10, 0), Color.Blue);
vertices[3] = new VertexPositionColor(new Vector3(-10, +10, 0), Color.Green);
vertices[4] = new VertexPositionColor(new Vector3(+10, +10, 0), Color.White);
vertices[5] = new VertexPositionColor(new Vector3(+10, -10, 0), Color.Blue);
 
// 頂点データをGPUに送り込む
_vertexBuffer = new VertexBuffer(_graphics.GraphicsDevice, VertexPositionColor.VertexDeclaration, vertices.Length, BufferUsage.None);
_vertexBuffer.SetData(vertices);
</source>
 
描画するときは、GraphicsDeviceクラスのSetVertexBufferメソッドで読み出して、DrawPrimitivesメソッドで描画する。
別途[[インデックスバッファ]]を使用しているときはDrawPrimitivesメソッドではなくDrawIndexedPrimitivesメソッドを使うこと。
<source lang="csharp">
_graphics.GraphicsDevice.SetVertexBuffer(_vertexBuffer);
 
foreach (var pass in _effect.CurrentTechnique.Passes)
{
pass.Apply();
_graphics.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, _vertexBuffer.VertexCount / 3);
}
</source>
== 関連項目 ==
匿名利用者

案内メニュー