Grand Nagus
Member
- Joined
- Jan 7, 2004
- Messages
- 10
Oh boy! An active DirectX forum!
Hello, all. Im a seriously newbie DirectX coder (using Visual C++ .net), and Im probably going to ask some ridiculously simple questions every now and then (ya can pick on me, but please dont bash me for not knowing anything).
Heres my dilemma:
First off, I dont know much of anything about DirectX programming. So far, I can kickstart DirectX in windowed and fullscreen at a set resolution and color mode (oooooh, impressive).
Ive played around with Microsofts tutorials to see how to do the basics, and it seemed easy enough. But Ive spent a couple of days trying to modify this tutorial to get it to render a quad (square) instead of a triangle. Heres what Ive done to it, but it doesnt work:
I changed this:
to this (added an extra vertex, arranged coords to reflect a square instead of a triangle):
Then, I changed this:
to this (increased buffer size to take into account the extra vertex):
Finally, I changed this:
to this (make a triangle strip instead of a triangle list, and make two polys):
That shoulda defined 4 vertices, put em into the vertex buffer, and then rendered em as a triangle strip instead of a triangle list. But when the programs run, it only shows a blue screen (the initialized DirectX screens background color). When I look at the code it looks like it should work, so I cant figure out where the problems at... Im sure its something really simple, but what am I doing wrong or omitting thats keeping this code from rendering a quad?
Thanks in advance for the help!
Hello, all. Im a seriously newbie DirectX coder (using Visual C++ .net), and Im probably going to ask some ridiculously simple questions every now and then (ya can pick on me, but please dont bash me for not knowing anything).
Heres my dilemma:
First off, I dont know much of anything about DirectX programming. So far, I can kickstart DirectX in windowed and fullscreen at a set resolution and color mode (oooooh, impressive).
Ive played around with Microsofts tutorials to see how to do the basics, and it seemed easy enough. But Ive spent a couple of days trying to modify this tutorial to get it to render a quad (square) instead of a triangle. Heres what Ive done to it, but it doesnt work:
I changed this:
Code:
// Initialize three vertices for rendering a triangle
CUSTOMVERTEX vertices[] =
{
{ 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
{ 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, },
{ 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },
};
Code:
// Initialize three vertices for rendering a triangle
CUSTOMVERTEX vertices[] =
{
{ 50.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
{ 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, },
{ 250.0f, 50.0f, 0.5f, 1.0f, 0xff00ffff, },
{ 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },
};
Then, I changed this:
Code:
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
Code:
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 2*3*sizeof(CUSTOMVERTEX),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
Finally, I changed this:
Code:
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
Code:
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
That shoulda defined 4 vertices, put em into the vertex buffer, and then rendered em as a triangle strip instead of a triangle list. But when the programs run, it only shows a blue screen (the initialized DirectX screens background color). When I look at the code it looks like it should work, so I cant figure out where the problems at... Im sure its something really simple, but what am I doing wrong or omitting thats keeping this code from rendering a quad?
Thanks in advance for the help!