Skip to main content
GameDev.net gamedev.net
🔒 Locked

Dynamic vertexbuffer data allocation

Started by turd7000 Feb 17, 2007 at 4:39 PM 2 replies 650+ views
Original Post
turd7000
turd7000
Basically I need to create and display vertexbuffers using data which is dynamically received at different points of the program, that is, I receive points and display them using vertexbuffers. The problem is that I'm a DirectX noob, and every vertexbuffer I create, regardless of where it is in the class structure, has the structure of the vertexbuffer created in the OnCreateVertexBuffer function. I've tried a whole bunch of things to resolve this with the end result being either nothing being drawn or that one vertexbuffer. Does anyone know how to display multiple vertexbuffers, with points generated as the program is running?
jollyjeffers
jollyjeffers
Sounds to me like you have a programming error - more details will be useful.

Create many IDirect3DVertexBuffer9's and make sure you switch the source using SetStreamSource(), thats all it should take. Usual pointer rules apply in this sense - don't overwrite pointers, don't dereference the wrong things etc...

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
turd7000
turd7000
I should have mentioned I'm using Managed DirectX, and that OnCreateVertexBuffer has the following usage in the program.

Header:
public void OnCreateVertexBuffer(object sender, EventArgs e)

Call:
vertexBuffer.Created += new System.EventHandler(this.OnCreateVertexBuffer);
this.OnCreateVertexBuffer(vertexBuffer, null);

I am creating multiple vertexbuffers, but whenever they draw, the structure is the same as the vertexbuffer created in the OnCreateVertexBuffer function. None of my attempts to create the vertexbuffers in other functions have resulted in those buffers being drawn. I've even tried to create vertexbuffers in other classes, with a different OnCreateVertexBuffer function, to no avail, the same vertexbuffer draws. I'm completely lost.

Are there no examples out there of dynamically allocated vertexbuffers using MDX? Or just two or more vertexbuffers not made in OnCreateVertexBuffer, but still using a recent version of MDX? I haven't been able to find any.
turd7000
turd7000
So, I think I've come up with a solution. It's a hack, and I'd rather do it a different way but I'm at an utter loss of reference material so I have little to no idea what happens behind the code.

So, assuming I can only have one big vertexbuffer, I'll just use one big vertexbuffer and draw pieces, ranges of vertices, of it at a time. The pieces will have their own transformation matrices. So my question is, when I call...

device.SetStreamSource(0, vertexBuffer, 0);
device.Transform.World = Matrix.Translation(0f, 0f, 5f);
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 12);

is the matrix transformation only applied to the vertices I'm drawing or to the entire vertexbuffer? I'm hoping it's the former. Furthermore, am I correct in assuming that vertexbuffers cannot be increased in size without constructing again?

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.