// 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();
#1 GDNet+ - Reputation: 521
Posted 06 January 2013 - 06:24 PM
#2 Members - Reputation: 571
Posted 06 January 2013 - 08:25 PM
Nice code, but did you have a question? ![]()
#4 Members - Reputation: 301
Posted 06 January 2013 - 08:52 PM
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
#6 Members - Reputation: 2109
Posted 07 January 2013 - 12:15 AM
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.






