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

tetris vertex buffer

Started by Digiflo Jul 3, 2006 at 4:47 AM 2 replies 1k views
Original Post
Digiflo
Digiflo
Hi, I recently finished a pong clone and for that the vertex buffer was a fixed size since the number of quads being drawn was constant. Now for tetris the number of quads will change as more blocks appear. I am hoping to make the vertex buffer dynamic, so it changes size as more blocks need to be drawn. To do this i hope to make the block 'objects' contain vertices for their positions. I was wondering how the best way to store the vertices in the object is and how to copy the vertices into the vertex buffer. My apologies if this isn't very clear, i'm new to both programming (using vc express btw) and directx. Thanks in advance.
dave
dave
Hey bud,

To be honest there is a maximum number of vertices here, it's something like the maximum number of smallest blocks times 2. I would be tempted to create a vertex buffer to accomodate this and then just keep track carefully of what you are rendering from it.

Since you are not going to be dealing with all that many vertices this would probably be the best solution.

Dave
Digiflo
Digiflo
Thanks Dave. I considered that approach before and i'm sure i could implement it, however i wanted to try and make my tetris game a sort of platform to build my next project (a side scroller) from.
I'm pretty sure that for a side scroller the vertex buffer would have to be dynamic. Then again i'm probably wrong...
Or if someone could share the concept they use for larger games for putting all the vertices into the vertex buffer, it would save me a lot of head scratching.
The 89 Vision
The 89 Vision
I'd recommend using a single 1 x 1 vertex buffer, and having each game object store its own texture(preferably reference to), width, height, location, and rotation.

Before you render each object, you'll need to do something like this.

D3DXMATRIX matRot, matTrans, matScale, matWorld;
D3DXMatrixRotationZ( &matRot, m_fThisObjectsOrientationInRadians );
D3DXMatrixTranslation( &matTrans, m_fThisObjectsXWorldLocation, m_fThisObjectsYWorldLocation, 0 );
D3DXMatrixScaling( &matScale, m_fObjectWidth, m_fObjectHeight, 1.0f );

matWorld = matScale * matRot * matTrans;
pd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

Then set the texture and render the object.

Hope that helps.

Topic Locked

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

Sign in to reply to this topic.