Jump to content
  • Advertisement


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


DX8.1 DrawPrimitive() or MeshBuilder?

This topic is 6080 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

Im trying to port an old example of a 3D person game, which was written in DirectX 3.0 (Retain Mode) from a book. In the code they use the MeshBuilder to draw the walls, floors and ceilings. Is this still the right path to take with DX 8.1 or should I be trying to use the DrawPrimitive() method. Also anyone found any good tutorials that on DX8.1 for this sort of stuff. I have searched high and low, have brought dozens of books, but all fail to point me in the right direction of making 3D games except for this one that uses DirectX 3.0...lol

Share this post

Link to post
Share on other sites
When I started using DirectX8 I went straight to the tutorials in the SDK. These provide you with enough info to get you started in 3D development using DrawPrimitive.

As far as I''m now aware Retained Mode and Immediate Mode are a thing of the past. Being poor, however, and never being able to afford a Modelling program nor have the skill to operate one I''ve always stuck to Immediate mode or DrawPrimitive as it is now.

Using the things I learnt in the SDK tutorials (which was matrices, how to draw a triangle, how to texture that triangle etc....real simple stuff) :- I managed to build a game that so far has made me profits in the thousands having sold it for £5 a shot at college. Okay - the game was real simple - it builds levels out of bitmaps (a bit like Wolfenstein 1) and has walls that are a right angles to each other but it looks good and is fun to play.

I learnt all that just reading the SDK. At the time I had no interent access nor the cash to buy books. A friend downloaded the SDK for me.

Basically - if you want to write a 3D FPS on your own - play Wolfenstein 1 a bit (you can still grab the Demo from ID Software..), learn to draw a triangle and move on from there. Generate your levels using maths and bitmaps (like and RPG)(which is quite easy).

When you''ve done that read the bit''s on the SDK about importing .x models into your apps and maybe go on from there.

At the end of the day all people have got their info from the SDK so really that''s all you need.

Hope this helps a little.


Share this post

Link to post
Share on other sites
Yeah, I did that, but kept having problems with the DrawPrimitive.

For example I tried to draw the ceiling above a hall way, extending on from the triangle. basically two right angle triangles stuck to the sides of a rectangle.
However no matter wot I try the last point I plot always ends up being in the top left hand corner .... I just cant work out why.

Heres my code

// Initialize three vertices for rendering a triangle

CUSTOMVERTEX g_Vertices[] =
{ 50.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
{ 100.0f, 50.0f, 0.5f, 1.0f, 0xff00ff00, },
{ 100.0f, 100.0f, 0.5f, 1.0f, 0xff0000ff, },

{ 100.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
{ 200.0f, 50.0f, 0.5f, 1.0f, 0xff00ff00, },
{ 200.0f, 100.0f, 0.5f, 1.0f, 0xff0000ff, },

{ 200.0f, 100.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
{ 100.0f, 100.0f, 0.5f, 1.0f, 0xff00ff00, },
{ 100.0f, 50.0f, 0.5f, 1.0f, 0xff0000ff, },

{ 200.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
{ 250.0f, 50.0f, 0.5f, 1.0f, 0xff00ff00, },
{ 200.0f, 100.0f, 0.5f, 1.0f, 0xff0000ff, },


// Create the vertex buffer. Here we are allocating enough memory
// (from the default pool) to hold all our 3 custom vertices. We also
// specify the FVF, so the vertex buffer knows what data it contains.
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 2*12*sizeof(CUSTOMVERTEX),
return E_FAIL;

// Now we fill the vertex buffer. To do this, we need to Lock() the VB to
// gain access to the vertices. This mechanism is required becuase vertex
// buffers may be in device memory.
VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, sizeof(g_Vertices), (BYTE**)&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );

return S_OK;

VOID Render()
// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );

// Begin the scene

// Draw the triangles in the vertex buffer. This is broken into a few
// steps. We are passing the vertices down a "stream", so first we need
// to specify the source of that stream, which is our vertex buffer. Then
// we need to let D3D know what vertex shader to use. Full, custom vertex
// shaders are an advanced topic, but in most cases the vertex shader is
// just the FVF, so that D3D knows what type of vertices we are dealing
// with. Finally, we call DrawPrimitive() which does the actual rendering
// of our geometry (in this case, just one triangle).
g_pd3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
g_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 12 );

// End the scene

// Present the backbuffer contents to the display
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );

Codes based on the Vertices example in the SDK.
Any Ideas wot Im doing wrong?

Share this post

Link to post
Share on other sites
I only glanced over the code and didn''t visualise the layout of the vertices (sorry, no time right now), but a) make sure the vertices are laid out for displaying triangle strips (you can double check by looking up primitive types in the docs). If you set up your vertices for one type and render using another it can all go to mush.

Also you''re using the RHW flags in your vertex definition (top of that sample app). As a result this will only display the vertices in local screen coordinates instead of true 3d z-space, if my memory serves me. Remove the RHW flags from your vertex structure and FVF definition and it should appear properly.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!