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

drawing triangle using dx9

Started by phil67rpg Jan 7, 2013 at 12:24 AM 5 replies 2.5k views
Original Post
phil67rpg
phil67rpg
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();
Postie
Postie

Nice code, but did you have a question? :)

[size="2"]Currently working on an open world survival RPG - For info check out my Development blog:[size="2"] ByteWrangler
phil67rpg
phil67rpg
yes I have drawn a triangle but I want to change it to a square during runtime.
EduardoMoura
EduardoMoura

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)

Check out my new blog: Morphexe 
Khatharr
Khatharr
Phil got the code tags working! +1!

Let us know how it turns out, bud. smile.png
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
Endurion
Endurion
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.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
phil67rpg
phil67rpg
thanks a lot I got it working also thanks for the rep points

Topic Locked

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

Sign in to reply to this topic.