Getting Started. XNA Game Studio 4.0 To download XNA Game Studio 4.0 itself, go to XNA Game.
XNA L04–Primitives, IndexBuffer and VertexBuffer
-
Upload
mohammad-shaker -
Category
Technology
-
view
320 -
download
2
Transcript of XNA L04–Primitives, IndexBuffer and VertexBuffer
![Page 1: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/1.jpg)
Mohammad Shakermohammadshaker.com
@ZGTRShaker2011, 2012, 2013, 2014
XNA Game DevelopmentL04 – Primitives, IndexBuffer and VertexBuffer
![Page 2: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/2.jpg)
3D World
![Page 3: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/3.jpg)
3D World
![Page 4: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/4.jpg)
3D World
![Page 5: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/5.jpg)
Primitives
• 1 - Drawing Triangles
• 2 - A Little Practice
• 3 - Index and Vertex Buffers
• 4 - Primitive Types
![Page 6: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/6.jpg)
Primitives
![Page 7: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/7.jpg)
Drawing Triangles
![Page 8: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/8.jpg)
Drawing TrianglesWhat do we need to draw?!
![Page 9: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/9.jpg)
Drawing Triangles
App1-Triangles
![Page 10: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/10.jpg)
Drawing Triangles
Initialize
LoadContent
UnloadContent
Update
Draw
Game1
![Page 11: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/11.jpg)
Drawing Triangles
• Global ScopeSpriteBatch spriteBatch;
VertexPositionColor[] vertices;
BasicEffect basicEffect;
Matrix world = Matrix.CreateTranslation(0, 0, 0);
Matrix view = Matrix.CreateLookAt(
new Vector3(0, 0, 3),
new Vector3(0, 0, 0),
new Vector3(0, 1, 0));
Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
800f / 600f,
0.01f,
100f);
![Page 12: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/12.jpg)
Drawing Triangles
SpriteBatch spriteBatch;
VertexPositionColor[] vertices;
BasicEffect basicEffect;
Matrix world = Matrix.CreateTranslation(0, 0, 0);
Matrix view = Matrix.CreateLookAt(
new Vector3(0, 0, 3),
new Vector3(0, 0, 0),
new Vector3(0, 1, 0));
Matrix projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45),
800f / 600f,
0.01f,
100f);
![Page 13: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/13.jpg)
Drawing Triangles
• LoadContent()
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
basicEffect = new BasicEffect(GraphicsDevice);
vertices = new VertexPositionColor[3];
vertices[0] = new VertexPositionColor(new Vector3(0, 1, 0), Color.Red);
vertices[1] = new VertexPositionColor(new Vector3(+0.5f, 0, 0), Color.Green);
vertices[2] = new VertexPositionColor(new Vector3(-0.5f, 0, 0), Color.Blue);
}
![Page 14: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/14.jpg)
Drawing Triangles
• LoadContent()
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
basicEffect = new BasicEffect(GraphicsDevice);
vertices = new VertexPositionColor[3];
vertices[0] = new VertexPositionColor(new Vector3(0, 1, 0), Color.Red);
vertices[1] = new VertexPositionColor(new Vector3(+0.5f, 0, 0), Color.Green);
vertices[2] = new VertexPositionColor(new Vector3(-0.5f, 0, 0), Color.Blue);
}
![Page 15: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/15.jpg)
Drawing Triangles
• Draw()
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
basicEffect.World = world;
basicEffect.View = view;
basicEffect.Projection = projection;
basicEffect.VertexColorEnabled = true;
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives<VertexPositionColor>
(PrimitiveType.TriangleList, vertices, 0, 1);
}
base.Draw(gameTime);
}
![Page 16: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/16.jpg)
Drawing Triangles
App1-Triangles
![Page 17: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/17.jpg)
Drawing Triangles
• Cube
![Page 18: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/18.jpg)
Different Primitive Types
![Page 19: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/19.jpg)
Different Primitive Types
• PrimitiveType.Points
• PrimitiveType.LineList
• PrimitiveType.LineStrip
• PrimitiveType.TriangleList
• PrimitiveType.TriangleStrip
• PrimitiveType.TriangleFan
![Page 20: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/20.jpg)
Different Primitive Types
![Page 21: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/21.jpg)
Different Primitive Types
![Page 22: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/22.jpg)
Different Primitive Types
![Page 23: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/23.jpg)
Different Primitive Types
![Page 24: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/24.jpg)
Drawing Triangles
• Using TrianglesList
• App2-Tetrahedron-TriangleList
![Page 25: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/25.jpg)
Drawing Triangles
• How to do it with a simple
rotation?!
![Page 26: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/26.jpg)
Drawing Triangles
• How to do it with a simple rotation?!
• First, What’s that 3D Object is?!
Tetrahedron! (Faces: 4, Vertices: 12)
![Page 27: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/27.jpg)
Drawing Triangles
• How to do it with a simple rotation?!
• First, What’s that 3D Object is?!
Tetrahedron! (Faces: 4, Vertices: 12(Each one at a time or a one shot?!))
![Page 28: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/28.jpg)
Drawing Triangles
• How to do it with a simple rotation?!
• First, What’s that 3D Object is?!
Tetrahedron! (Faces: 4, Vertices: 12(use TriangleList))
![Page 29: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/29.jpg)
Drawing Triangles – Simple Rotation
• How to do it with a simple rotation?!
vertices = new VertexPositionColor[12];
vertices[0] = new VertexPositionColor(new Vector3(0.000f, 1.000f, 0.000f), Color.Red);
vertices[1] = new VertexPositionColor(new Vector3(-0.816f, -0.333f, -0.471f), Color.Blue);
vertices[2] = new VertexPositionColor(new Vector3(0.000f, -0.333f, 0.943f), Color.Green);
vertices[3] = new VertexPositionColor(new Vector3(0.000f, 1.000f, 0.000f), Color.Red);
vertices[4] = new VertexPositionColor(new Vector3(0.816f, -0.333f, -0.471f), Color.Yellow);
vertices[5] = new VertexPositionColor(new Vector3(-0.816f, -0.333f, -0.471f), Color.Blue);
vertices[6] = new VertexPositionColor(new Vector3(0.000f, -0.333f, 0.943f), Color.Green);
vertices[7] = new VertexPositionColor(new Vector3(0.816f, -0.333f, -0.471f), Color.Yellow);
vertices[8] = new VertexPositionColor(new Vector3(0.000f, 1.000f, 0.000f), Color.Red);
vertices[9] = new VertexPositionColor(new Vector3(-0.816f, -0.333f, -0.471f), Color.Blue);
vertices[10]= new VertexPositionColor(new Vector3(0.816f, -0.333f, -0.471f), Color.Yellow);
vertices[11] = new VertexPositionColor(new Vector3(0.000f, -0.333f, 0.943f), Color.Green);
VertexPositionColor[] vertices;
![Page 30: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/30.jpg)
Drawing Triangles – Simple Rotation
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
basicEffect.World = world;
basicEffect.View = view;
basicEffect.Projection = projection;
basicEffect.VertexColorEnabled = true;
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 4);
}
base.Draw(gameTime);
}
![Page 31: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/31.jpg)
Drawing Triangles – Simple Rotation
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
basicEffect.World = world;
basicEffect.View = view;
basicEffect.Projection = projection;
basicEffect.VertexColorEnabled = true;
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 4);
}
base.Draw(gameTime);
}
![Page 32: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/32.jpg)
Drawing Triangles – Simple Rotation
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
basicEffect.World = world;
basicEffect.View = view;
basicEffect.Projection = projection;
basicEffect.VertexColorEnabled = true;
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 4);
}
base.Draw(gameTime);
}
![Page 33: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/33.jpg)
Drawing Triangles – Simple Rotation
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
basicEffect.World = world;
basicEffect.View = view;
basicEffect.Projection = projection;
basicEffect.VertexColorEnabled = true;
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 4);
}
base.Draw(gameTime);
}
![Page 34: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/34.jpg)
Drawing Triangles – Rotation Logic
![Page 35: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/35.jpg)
Drawing Triangles – Rotation LogicMatrices and Transformations
![Page 36: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/36.jpg)
Drawing Triangles
• Using TrianglesList
• App3-TriangleList
![Page 37: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/37.jpg)
Different Primitive Types
• Changing last tutorial PrimitiveType to LineList will result in
• “App5-VertexBuffer-LineList”
![Page 38: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/38.jpg)
Index And Vertex Buffers
![Page 39: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/39.jpg)
Index And Vertex BuffersThe Concept
![Page 40: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/40.jpg)
Index And Vertex Buffers
• Effectively store our data
• Greatly reduce the amount of data that needs to be send over to the graphics
device
– speed up our applications a looooooooooot!
• The only way to store your data
![Page 41: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/41.jpg)
Index And Vertex Buffers• Look at this,
![Page 42: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/42.jpg)
Index And Vertex Buffers
True oder false?
• Look at this,
![Page 43: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/43.jpg)
Index And Vertex Buffers
True oder false?
• Look at this,
![Page 44: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/44.jpg)
Index And Vertex Buffers
![Page 45: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/45.jpg)
Index And Vertex Buffers
![Page 46: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/46.jpg)
Index And Vertex Buffers
![Page 47: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/47.jpg)
Index And Vertex Buffers
![Page 48: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/48.jpg)
Index And Vertex Buffers – The Creating of
• An Icosahedron
![Page 49: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/49.jpg)
Index And Vertex Buffers – The Creating of
• An Icosahedron
• “App4-VertexBuffer”
![Page 50: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/50.jpg)
Index And Vertex Buffers – The Creating of
• Creating the Necessary Variables
VertexBuffer vertexBuffer;
IndexBuffer indexBuffer;
![Page 51: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/51.jpg)
Index And Vertex Buffers – The Creating of
• Creating the Necessary Variables
VertexBuffer vertexBuffer;
IndexBuffer indexBuffer;
VertexPositionColor[] vertices;
![Page 52: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/52.jpg)
Index And Vertex Buffers – The Creating of
• Creating the Necessary Variables
VertexBuffer vertexBuffer;
IndexBuffer indexBuffer;
VertexPositionColor[] vertices; // Needed in a global scope or not?
![Page 53: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/53.jpg)
Index And Vertex Buffers – The Creating of
• Creating the Necessary Variables
VertexBuffer vertexBuffer;
IndexBuffer indexBuffer;
VertexPositionColor[] vertices; // Needed in a global scope or not?
![Page 54: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/54.jpg)
Index And Vertex Buffers – The Creating of
• In LoadContent()VertexPositionColor[] vertexArray = new VertexPositionColor[12];
// vertex position and color information for icosahedron
vertexArray[0] = new VertexPositionColor(new Vector3(-0.26286500f, 0.0000000f, 0.42532500f), Color.Red);
//…..
vertexArray[11]= new VertexPositionColor(new Vector3(-0.42532500f, -0.26286500f, 0.0000000f),Color.Crimson);
// Set up the vertex buffer
vertexBuffer = new VertexBuffer( graphics.GraphicsDevice,
typeof(VertexPositionColor),
vertexArray.Length,
BufferUsage.WriteOnly);
vertexBuffer.SetData(vertexArray);
short[] indices = new short[60];
indices[0] = 0; indices[1] = 6; indices[2] = 1;
//…
indices[57] = 9; indices[58] = 11; indices[59] = 0;
indexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(short), indices.Length, BufferUsage.WriteOnly);
indexBuffer.SetData(indices);
![Page 55: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/55.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 56: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/56.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 57: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/57.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 58: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/58.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 59: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/59.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 60: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/60.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 61: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/61.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 62: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/62.jpg)
![Page 63: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/63.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 64: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/64.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 65: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/65.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 66: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/66.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 67: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/67.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 68: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/68.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 69: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/69.jpg)
Index And Vertex Buffers
• In Draw() Method
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.Indices = indexBuffer;
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 12, 0, 20);
}
![Page 70: XNA L04–Primitives, IndexBuffer and VertexBuffer](https://reader034.fdocuments.net/reader034/viewer/2022042601/5553b560b4c905d4448b4cf1/html5/thumbnails/70.jpg)
Index And Vertex Buffers
• An Icosahedron at last
has been built!