Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Adding more vertices to my vertex buffer

This topic is 5901 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I''ll just show the code to explain what I''m trying to do; (sVertex has x,y,z and u,v coords) sVertex Verts[] = { { 0.0f, 500.0f, 400.0f, 1.0f, 0.0f }, {400.0f, 500.0f, 400.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 400.0f, 1.0f, 1.0f }, {400.0f, 0.0f, 400.0f, 0.0f, 1.0f } }; Verts[5] = (sVertex){500.0f, 500.0f, 400.0f, 1.0f, 0.0f }; Verts[6] = .... etc this obviously doesn''t work. How should I append more vertices to my array?

##### Share on other sites
There are several ways to do what you want. The easiest way for me to tell you how is to include the header file vector, and use that (that being a vector). STL containers are platform independant STANDARD TEMPLATE LIBRARY data structures.

I started to try to walk you though how to do this, but unless you know how to use templates, I don't see how I coule help you use vectors...

Another way to do what you want is to have one array created dynamically, and have it copy all of the old elements then add a new one. Then if you have to add another you just create another dynamic array and delete the old one. One way is to create your own array class (that does all the allocation/deallocation of the arrays and overload operators so that you can copy and add an element using one operator ( such as =+ )). This way you could just have an assignment like (assuming you name the class Array)

      Array verts(25);  // have your class use the argument as the size                  // of your array.verts =+ verts(1.0f);  // have the operator overloaded and return                       // the argument to allow cascading.

If you implement this in your class the right way, your program would look like you are using a built in data type.

Good luck!

edit: the include vector went away.

If at first you don't succeed, use profanity and try, try again.

[edited by - grandmlee on April 29, 2002 7:27:44 AM]

##### Share on other sites
Dynamically allocating a new array every time I want to add some vertices would probably be very slow, right? So I guess I''ll have to look into the STL vector.. Thanks for your help!

##### Share on other sites
OK, I set up a vector for my vertices like this:
vector'<'sVertex'>' Verts;

Then I pushed_back some vertices on the vector, created a vertex buffer and tried to copy the contents of the vector to the vertex buffer. Like this:

memcpy(Ptr, Verts, sizeof(Verts));
(between calls to lock and unlock ofcourse)

This doesn't work.. what am I doing wrong? How should I copy the vertices to the vertex buffer?

edit: '<'sVertex'>' disappeared

[edited by - Sponzie on April 29, 2002 9:15:29 AM]

[edited by - Sponzie on April 29, 2002 9:16:32 AM]

##### Share on other sites
I couldn''t figure out how to copy the vector to the vertexbuffer directly, so i created a dynamic array (of the vector''s size), copied the contents of the vector to the array, and finally copied the array to the VB. There must be a simpler solution, but until i hear one i''m gonna have to stick to this

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631434
• Total Posts
3000048
×

## Important Information

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!