Sign in to follow this  
vatsadevil

Creating multiple instances of same set of vertices?

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this