Jump to content
  • Advertisement
Sign in to follow this  
vatsadevil

Creating multiple instances of same set of vertices?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi. i'm trying to make a 2d game in directx. i have created a small square using 4 vertices. i want lot of exactly same kind of squares, with the same textures. this is how i create the boxes.. void spaceship1(void) { D3DXCreateTextureFromFile(d3ddev,L"wood1.png",&texture2); CUSTOMVERTEX vertices2[] = { { -1.0f, 1.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 0.0f,0.0f,}, { 1.0f, 1.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255),1.0f,0.0f, }, { -1.0f, -1.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255),0.0f,1.0f, }, { 1.0f, -1.0f, 0.0f, D3DCOLOR_XRGB(255, 255, 255),1.0f,1.0f, }, }; d3ddev->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX),0,CUSTOMFVF,D3DPOOL_MANAGED, &v_buffer2, NULL); VOID* pVoid; v_buffer2->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, vertices2, sizeof(vertices2)); v_buffer2->Unlock(); } i'm sure there's a way to just create instances of the same thing multiple times instead of making new function for each and every box.. if any1 could help, it would be great!! thx..

Share this post


Link to post
Share on other sites
Advertisement
Just call d3ddev->Draw multiple times, with the same vertex buffer. To have the boxes at different positions, or with different transformations such as rotations, just use a different world matrix for each when drawing.

Share this post


Link to post
Share on other sites
oh..damn.. yeahhh, how silly of me.. thx a lot..it works now.. i have another question.. how do i delete one of those boxes.. for example, when i press UP key, one particular box shud disappear.. how do i do that??

Share this post


Link to post
Share on other sites
Quote:
how do i delete one of those boxes.. for example, when i press UP key, one particular box shud disappear.. how do i do that??
Just stop rendering that particular box?

If you're asking how to remove the object from the simulation, then that's both language- and implementation-dependent. In C++, for example, you might erase an element from a vector object. Other options would include 'flagging' the object as inactive, or manually reallocating memory and/or relocating data so that the object no longer exists.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!