開発環境 |
Microsoft Visual C# 2010 Express (SP1) |
実行環境 |
Microsoft Windows XP Home Edition (SP3) |
プロジェクトの種類 |
空のプロジェクト |
プロジェクト名 |
IndexBuffer |
プロジェクトの保存
[ソリューションのディレクトリを作成]はチェックを付けなくてもいい。
プロジェクトのプロパティ
[アプリケーション]タブ
出力の種類:Windows アプリケーション
プロジェクトにクラスを追加する。
テンプレート:クラス
名前:TestGame.cs
参照設定に以下の
.NET参照を追加する。
Microsoft.Xna.Framework
Microsoft.Xna.Framework.Game
Microsoft.Xna.Framework.Graphics
参考
TestGame.cs
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
class TestGame : Game
{
static void Main()
{
using (Game game = new TestGame())
{
game.Run();
}
}
GraphicsDeviceManager graphics;
VertexBuffer vertexBuffer;
IndexBuffer indexBuffer;
BasicEffect effect;
VertexPositionColor[] vertices;
short[] indices;
TestGame()
{
graphics = new GraphicsDeviceManager(this);
}
protected override void Initialize()
{
vertices = new VertexPositionColor[] {
new VertexPositionColor(new Vector3(-0.5f, 0.5f, 0), Color.Red),
new VertexPositionColor(new Vector3(0.5f, 0.5f, 0), Color.Blue),
new VertexPositionColor(new Vector3(-0.5f, -0.5f, 0), Color.Lime),
new VertexPositionColor(new Vector3(0.5f, -0.5f, 0), Color.Black),
};
indices = new short[] { 0, 1, 2, 1, 3, 2 };
base.Initialize();
}
protected override void LoadContent()
{
vertexBuffer = new VertexBuffer(GraphicsDevice,
typeof(VertexPositionColor), vertices.Length, BufferUsage.None);
vertexBuffer.SetData(vertices);
GraphicsDevice.SetVertexBuffer(vertexBuffer);
indexBuffer = new IndexBuffer(GraphicsDevice,
IndexElementSize.SixteenBits, indices.Length, BufferUsage.None);
indexBuffer.SetData(indices);
GraphicsDevice.Indices = indexBuffer;
effect = new BasicEffect(GraphicsDevice);
effect.VertexColorEnabled = true;
base.LoadContent();
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, 2);
}
base.Draw(gameTime);
}
}
最終更新:2012年11月29日 20:37