「MonoGame/クラスライブラリ/VertexBufferクラス」の版間の差分

imported>Administrator
ページの作成:「VertexBufferクラスは、ポリゴンを表示するのに使う頂点のリストである。 MonoGameでは頂点構造体を単純な配列で保持して...」
 
imported>Administrator
編集の要約なし
 
145行目: 145行目:
| (GameResourceクラスから継承)
| (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>


== 関連項目 ==
== 関連項目 ==