vertex questions

Started by
2 comments, last by jnye 19 years, 2 months ago
I am learning Direct3d by creating a clone of BoulderDash, an old game from atari and comador systems. I have the game working, in fact I have gone through several versions, first using directdraw and now using direct3d. I am creating a textured quad for each tile on the map, for each character of text, and for icons and windows. I use two vertex buffers, one for RHW vertex and another without RHW. Here are my questions... Is is possible to just store the vertex for each type of tile and draw it multiple times to various locations? If I can do this the vertex count will not change based on level size, amount of text, or window count. Harry J. Kuhar
Advertisement
Quote:Original post by kuharh
Is is possible to just store the vertex for each type of tile and draw it multiple times to various locations?


Yes it is using a matrix and setting up an orthograghic view(it sounds more complex than it really is). I suggest you read this. You could create only one textured quad of each size of tile and then change the matrix position of each one you want to draw. This will probably result in more DrawPrimitive calls though and depending on your video card may slow things down.

Quote:Original post by kuharh
If I can do this the vertex count will not change based on level size, amount of text, or window count.


If you only had three different sizes of tiles you could actually lower the vertex count to 12. However this would mean drawing tiles one by one. A faster way would be to have a few textured quads in each VB so you can draw a few at once.


Text might be able to stay with RHW but you're going to have to learn how to use matrices if you want scrolling of moving sprites since locking the VB is really really slow.
I have been poking around in the DirectX SDK documentation and found a sections titled "Efficiently Drawing Multiple Instances of Geometry". This seems to be what I am trying to do. It sugests using indexed geometry and two vertex buffers per FVF, one for geometry and another for instances. It says that the hardware needs to support the "3_0 vertex shader model". Is this standard now or is there a way around it?
Anyway from what I understand you keep your geometry in one buffer and set that as stream 0 and store instances of the geometry in the other buffer and set that as stream 1. I will try to implement this approach tonight and see what I can come up with. Here is a code snip from the help file...

if( SUCCEEDED( pd3dDevice->BeginScene() ) )
{
// Set up the geometry data stream
pd3dDevice->SetStreamSourceFreq(0,
(D3DSTREAMSOURCE_INDEXEDDATA | g_numInstancesToDraw));
pd3dDevice->SetStreamSource(0, g_VB_Geometry, 0,
D3DXGetDeclVertexSize( g_VBDecl_Geometry, 0 ));

// Set up the instance data stream
pd3dDevice->SetStreamSourceFreq(1,
(D3DSTREAMSOURCE_INSTANCEDATA | 1));
pd3dDevice->SetStreamSource(1, g_VB_InstanceData, 0,
D3DXGetDeclVertexSize( g_VBDecl_InstanceData, 1 ));

pd3dDevice->SetVertexDeclaration( ... );
pd3dDevice->SetVertexShader( ... );
pd3dDevice->SetIndices( ... );

pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0,
g_dwNumVertices, 0, g_dwNumIndices/3 );

pd3dDevice->EndScene();
}



I'm trying to do something similar (see my recently posted thread "DirectX sprite performance") and would be interested to see how this turns out for you.

Let me know if you make any progress.

This topic is closed to new replies.

Advertisement