index buffer

Started by
5 comments, last by neneboricua19 18 years, 7 months ago
I can't seem to find the help for using an index buffer. Could someone point me in the right direction? Thanks, Devin
Advertisement
You need to be more specific. What are you having trouble with? In the most recent SDK (August 2005), there are a couple of pretty good topics explaining how to create index buffers and what the parameters to DrawIndexedPrimitive actually mean.

The topics in the SDK docs are "Index Buffers" and "Rendering from Vertex and Index Buffers"

neneboricua
this is what I have so far...

ib = new IndexBuffer(device, 192, Usage.None, Pool.Default, true);
ib.Lock(0, 0, LockFlags.None);
ib.SetData(p1.indices, 0, LockFlags.None);
ib.Unlock();
device.Indices = ib;

vb = new VertexBuffer(device, 288, Usage.None, CustomVertex.PositionColored.Format, Pool.Default);
GraphicsStream gstr = vb.Lock(0, 0, LockFlags.None);
gstr.Write(p1.verts);
vb.Unlock();
.
.
.

device.SetStreamSource(0, vb, 0);
device.VertexFormat = CustomVertex.PositionColored.Format;
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 18, 0, 32);
what do you need to know about idexBuffers?What do you want to do?anyway if you use ib.SetData(p1.indices, 0, LockFlags.None);,..you don't need lock and unlock.
Cool thanks, This doesn't actually show anything on the screen. Any ideas why? just blank screen, but if I don't use indexbuffer then it does show stuff on screen. I'm just wondering what I'm doing wrong.
there are 18 vertices and 96 indices, which create 32 triangles.

Quote:Original post by devronious
Cool thanks, This doesn't actually show anything on the screen. Any ideas why? just blank screen, but if I don't use indexbuffer then it does show stuff on screen. I'm just wondering what I'm doing wrong.

Then the data in your index buffer is probably incorrect.

If your buffers are set up so that you could just call DrawPrimitive on the original vertex buffers and everything is rendered fine, then your vertex buffer is probably set up so that each vertex needed for drawing the mesh is repeated however many times that is necessary. This will work but isn't as efficient as storing each vertex just once and using the index buffer to specify which vertices to use during rendering.

If its the case that your vertex buffer specifies all repeated vertices in the mesh itself, then the contents of your index buffer will probably be something like this:
{0,1,2,3,4,5,6,...}

neneboricua

This topic is closed to new replies.

Advertisement