• Advertisement
Sign in to follow this  

drawing triangle using dx9

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

I am studying the directx9tutorial.com web site.one of their exercises is to change the shape of a triangle during runtime. Here is some of the code given from this tutorial. // this is the function used to render a single frame void render_frame(void) { d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); d3ddev->BeginScene(); // select which vertex format we are using d3ddev->SetFVF(CUSTOMFVF); // select the vertex buffer to display d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX)); // copy the vertex buffer to the back buffer d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); } // this is the function that cleans up Direct3D and COM void cleanD3D(void) { v_buffer->Release(); // close and release the vertex buffer d3ddev->Release(); // close and release the 3D device d3d->Release(); // close and release Direct3D } // this is the function that puts the 3D models into video RAM void init_graphics(void) { // create the vertices using the CUSTOMVERTEX struct CUSTOMVERTEX vertices[] = { { 400.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), }, { 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), }, { 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), }, }; // create a vertex buffer interface called v_buffer d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL); VOID* pVoid; // a void pointer // lock v_buffer and load the vertices into it v_buffer->Lock(0, 0, (void**)&pVoid, 0); memcpy(pVoid, vertices, sizeof(vertices)); v_buffer->Unlock();

Share this post


Link to post
Share on other sites
Advertisement

Just few tips, a triangle has 3 vertices a square has 4 at least (you may need more).

Find where you declare vertices,

 

You will need a switch to check if you are in square mode or triangle mode, and to a way to change that switch at runtime. (By switch I mean a Bool variable, True, False)

Share this post


Link to post
Share on other sites
Just few tips, a triangle has 3 vertices a square has 4 at least (you may need more).

Find where you declare vertices,

 

You will need a switch to check if you are in square mode or triangle mode, and to a way to change that switch at runtime. (By switch I mean a Bool variable, True, False)

There is no square mode.

 

A square is simply a list of two triangles instead of 1. The simplest way would be to add the 3 vertices of the second triangle to your vertex array , change the "3*" in the CreateVertexBuffer call to "6*" and change the "1" in the DrawPrimitive call to "2".

Get that working first, don't bother with the other primitive types yet.

Share this post


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

  • Advertisement