| Topic: Using more than 1 VertexBuffer
|
|
 | Using more than 1 VertexBuffer | |  |
| Poster | : Nic-Gun | | Posts | : 3 | | Country | : Indonesia | | City | : Jakarta |
| | | | Posted by Nic-Gun on 11/05/2007 at 02:09:01
| | Hey there riemers, been going through your tutorials for a while and I came upon this one. I tried the Triangle Strip and it worked. but when I tried to use three VertexBuffer at once, this happened :

I was trying to make a cursor like object, shaped like this :

so I split a,b, and c into a VertexBuffer, d and e each into another VertexBuffer. the code is somthing like this :
verticesabc[0] = new VertexFormat(cursorPosition + new Vector3(-2.5f, -0.5f, 2.5f), Color.Blue);
verticesabc[1] = new VertexFormat(cursorPosition + new Vector3(-2.5f, -0.5f, -2.5f), Color.Blue);
verticesabc[2] = new VertexFormat(cursorPosition + new Vector3(-2.5f, 0, 2.5f), Color.Blue);
verticesabc[3] = new VertexFormat(cursorPosition + new Vector3(-2.5f, 0, -2.5f), Color.Blue);
verticesabc[4] = new VertexFormat(cursorPosition + new Vector3(2.5f, 0, 2.5f), Color.Blue);
verticesabc[5] = new VertexFormat(cursorPosition + new Vector3(2.5f, 0, -2.5f), Color.Blue);
verticesabc[6] = new VertexFormat(cursorPosition + new Vector3(2.5f, -0.5f, 2.5f), Color.Blue);
verticesabc[7] = new VertexFormat(cursorPosition + new Vector3(2.5f, -0.5f, -2.5f), Color.Blue);
verticesd[0] = new VertexFormat(cursorPosition + new Vector3(-2.5f, 0, -2.5f), Color.Yellow);
verticesd[1] = new VertexFormat(cursorPosition + new Vector3(-2.5f, -0.5f, -2.5f), Color.Yellow);
verticesd[2] = new VertexFormat(cursorPosition + new Vector3(2.5f, 0f, -2.5f), Color.Yellow);
verticesd[3] = new VertexFormat(cursorPosition + new Vector3(2.5f, -0.5f, -2.5f), Color.Yellow);
verticese[0] = new VertexFormat(cursorPosition + new Vector3(-2.5f, -0.5f, 2.5f), Color.Red);
verticese[1] = new VertexFormat(cursorPosition + new Vector3(-2.5f, 0, 2.5f), Color.Red);
verticese[2] = new VertexFormat(cursorPosition + new Vector3(2.5f, -0.5f, 2.5f), Color.Red);
verticese[3] = new VertexFormat(cursorPosition + new Vector3(2.5f, 0, 2.5f), Color.Red);
vbabc = new VertexBuffer(myGraphics.GraphicsDevice, VertexFormat.SizeInBytes * 8, ResourceUsage.WriteOnly);
vbabc.SetData(verticesabc);
vbd = new VertexBuffer(myGraphics.GraphicsDevice, VertexFormat.SizeInBytes * 4, ResourceUsage.WriteOnly);
vbd.SetData(verticesd);
vbe = new VertexBuffer(myGraphics.GraphicsDevice, VertexFormat.SizeInBytes * 4, ResourceUsage.WriteOnly);
vbe.SetData(verticese);
|
and then I call them at Draw() by using :
cursorEffect.CurrentTechnique = cursorEffect.Techniques["Colored"];
cursorEffect.Parameters["xView"].SetValue(ViewOnFocus);
cursorEffect.Parameters["xProjection"].SetValue(Projection);
cursorEffect.Parameters["xWorld"].SetValue(Matrix.Identity);
cursorEffect.Begin();
foreach (EffectPass pass in cursorEffect.CurrentTechnique.Passes)
{
pass.Begin();
myGraphics.GraphicsDevice.VertexDeclaration = new VertexDeclaration(myGraphics.GraphicsDevice, VertexFormat.Elements);
myGraphics.GraphicsDevice.Vertices[0].SetSource(vbabc, 0, VertexFormat.SizeInBytes);
myGraphics.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 8);
myGraphics.GraphicsDevice.Vertices[0].SetSource(vbd, 0, VertexFormat.SizeInBytes);
myGraphics.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 4);
myGraphics.GraphicsDevice.Vertices[0].SetSource(vbe, 0, VertexFormat.SizeInBytes);
myGraphics.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 4);
pass.End();
}
cursorEffect.End();
|
Anything wrong it it? thanks for the help. | |
|
| | | | | | Poster | : me26493 | | Posts | : 87 | | Country | : Australia | | City | : Melbourne |
| | | | Posted by me26493 on 12/05/2007 at 19:05:42
| | | You should really use one vertex buffer - and multiple index buffers. This is much easier (and saves memory) | |
|
| | | | | | Poster | : Nic-Gun | | Posts | : 3 | | Country | : Indonesia | | City | : Jakarta |
| | | | Posted by Nic-Gun on 13/05/2007 at 22:04:32
| | well index buffers are from Microsoft.DirectX.Direct3D and I'm already using Microsoft.XNA.Framework so they don't work out really well I think.
Any advice on how to merge those two? | |
|
| | | | | | Poster | : Nic-Gun | | Posts | : 3 | | Country | : Indonesia | | City | : Jakarta |
| | | | Posted by Nic-Gun on 14/05/2007 at 04:54:09
| | Forget I asked those questions. I just managed to solve the problem using indices, vertices and VertexPositionNormalTexture.
Now I'm curious about giving the object a transparent feel, or maybe a texture. can I do it on the run, or should I use the effect file? | |
|
| | | | | | Poster | : riemer | | Posts | : 1392 | | Country | : Belgium | | City | : Antwerp |
| | | | Posted by riemer on 16/05/2007 at 10:57:33
| | Sure you can use the effect file fore this; simply set the .a value of the color to 0.5f in the pixel shader.
Or you can simply change the color information in your vertices. Don't forget to enable alpha blending before drawing them though (also needed in case you use the effect file) | |
|
|
 | | |  |
|
|
|
If you appreciate the amount of time I spend creating and updating these pages, feel free to donate -- any amount is welcome !
|
- Website design & DirectX code : Riemer Grootjans - ©2006 Riemer Grootjans
|
|