Skip to main content
gamedev.net
🔒 Locked

VB problems

Started by Nuklear 1 reply 1.3k views
Original Post
Nuklear
Nuklear
I'm using directx9 with visual c++ and all the tutorial's that I have read show me how to create an object (spinnig triangle/cube etc) by manually entering all the vertices manually into a VB, then they go onto using sprites. This is all good but I want to draw multiple things to the screen, the amount of which will be changing. So I will be using a dynamic VB, however I'm not sure how to get my vertices into the VB. At the moment I'm planning on having a class that has it's own array holding the vertices for each object and then appending them to the main vertex buffer. To append the arrays i need to use something like strncat(), but that only works on strings and i can't find a function that I can use with my vertex buffer. Will I have to write my own function or have I not looked hard enough? Also is this the best way or is there a more common/simpler/efficient way to do it? Thanks in advance.
ReaVeR-Andrey
ReaVeR-Andrey
People say it is not a very good idea to regularly lock/unlock vertex/index buffers.
Your problem is solved like that:
1. Lock your vertex buffer (it can be done once for a frame). You obtain a pointer to vertex data.
2. Use memcpy to copy your vertex data to the end of your array: memcpy ( vb_pointer + num_already_written, source_pointer, num_to_write * sizeof ( vertex ) )
3. Unlock your vertex buffer (also once in a frame)
Nuklear
Nuklear
Thanks, looks like your way is much more straightforward to implement than what I was thinking of doing.
Funny how these things seem so obvious when you know how to do them.

Topic Locked

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

Sign in to reply to this topic.