Forum
Contact





DirectX using C#
DirectX using C++
DirectX using Visual Basic



Latest Forum posts

 No download link for 2d series: shooter
  Posted by: zaboleq
  When: 07/05/2013 at 15:46:28

 Collision Class?
  Posted by: Anonymous
  When: 05/05/2013 at 19:03:59

 stack overflow
  Posted by: cityguy
  When: 07/04/2013 at 01:58:38

 Meshes looks strange.
  Posted by: ab_saratov
  When: 01/04/2013 at 04:31:08

 Lamppost Not loaded
  Posted by: Anonymous
  When: 22/03/2013 at 06:43:52

 Collision Class?
  Posted by: Da_Boom
  When: 21/03/2013 at 01:23:09

 Math boggles me
  Posted by: cityguy
  When: 17/03/2013 at 03:44:48

 Collision Class?
  Posted by: Da_Boom
  When: 16/03/2013 at 03:44:42

 Tree update
  Posted by: Anonymous
  When: 15/03/2013 at 21:11:22

 XNA 4.0
  Posted by: Anonymous
  When: 15/03/2013 at 19:43:57

 Error when I try to run.
  Posted by: Anonymous
  When: 15/03/2013 at 19:21:06

 Error With the Effect File
  Posted by: Anonymous
  When: 15/03/2013 at 18:21:01

 Can only get shadowmap
  Posted by: Anonymous
  When: 15/03/2013 at 15:48:52

 Vertex and Pixel Shader Versions?
  Posted by: Anonymous
  When: 15/03/2013 at 15:07:16

 Unsupported properties
  Posted by: Anonymous
  When: 15/03/2013 at 14:23:00

 Problem Loading Skybox
  Posted by: Rana
  When: 15/03/2013 at 10:34:45

 Black Screen Of Death - Help!
  Posted by: Anonymous
  When: 15/03/2013 at 03:43:43

 2.0 anyone?
  Posted by: Anonymous
  When: 15/03/2013 at 02:19:48

 Defitinition of tha rotation axis
  Posted by: Anonymous
  When: 15/03/2013 at 00:55:14

 Typo / Inconsistancy for 360 deployment.
  Posted by: Anonymous
  When: 14/03/2013 at 19:48:23




Topic: Using more than 1 VertexBuffer



  
Goto parent category
  
Create a new user account


   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)

  
Post a new reply
 





Google
 
Web www.riemers.net
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


News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Opening a window
Linking to the Device
Drawing a triangle
Camera
Rotation - Translation
Indices
Terrain creation
Terrain from file
DirectInput
Importing bmp files
Colored vertices
DirectX Light basics
Mesh creation
Mesh lighting
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)