Grand Nagus
Newcomer
- Joined
- Jan 7, 2004
- Messages
- 10
Oh boy! An active DirectX forum!
Hello, all. I'm a seriously newbie DirectX coder (using Visual C++ .net), and I'm probably going to ask some ridiculously simple questions every now and then (ya can pick on me, but please don't bash me for not knowing anything).
Here's my dilemma:
First off, I don't 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).
I've played around with Microsoft's tutorials to see how to do the basics, and it seemed easy enough. But I've spent a couple of days trying to modify this tutorial to get it to render a 'quad' (square) instead of a 'triangle'. Here's what I've done to it, but it doesn't 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 program's run, it only shows a blue screen (the initialized DirectX screen's background color). When I look at the code it looks like it should work, so I can't figure out where the problem's at... I'm sure it's something really simple, but what am I doing wrong or omitting that's keeping this code from rendering a quad?
Thanks in advance for the help!
Hello, all. I'm a seriously newbie DirectX coder (using Visual C++ .net), and I'm probably going to ask some ridiculously simple questions every now and then (ya can pick on me, but please don't bash me for not knowing anything).
Here's my dilemma:
First off, I don't 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).
I've played around with Microsoft's tutorials to see how to do the basics, and it seemed easy enough. But I've spent a couple of days trying to modify this tutorial to get it to render a 'quad' (square) instead of a 'triangle'. Here's what I've done to it, but it doesn't 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 program's run, it only shows a blue screen (the initialized DirectX screen's background color). When I look at the code it looks like it should work, so I can't figure out where the problem's at... I'm sure it's something really simple, but what am I doing wrong or omitting that's keeping this code from rendering a quad?
Thanks in advance for the help!