Sign in to follow this  

DrawPrimitive: Triangle is missing pixels?

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

Okay, I'm using code from the DirectX9 tutorial for rendering a transformed triangle to the screen. I've have performed the tutorial in the past successfully, but this time its produced a rendering error... Basically, I have a triangle thats missing most of its pixels. The tutorial uses the DrawPrimitive() method, but I'm damn sure the setup of the vertex buffer is correct - otherwise I wouldn't have anything that resembles a triangle! Like I said - I've used the code so many times before, but this really has me stumped. Any ideas would be welcome...

Share this post


Link to post
Share on other sites
Okay, heres the globals involved for the vertex buffer...

////////////////////////////////////////////////////////////////////////////
struct CUSTOMVERTEX{
float x, y, z, rhw;
DWORD colour;
};

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, 0xff0000ff, },
};

LPDIRECT3DVERTEXBUFFER9 lineBuffer = NULL;

////////////////////////////////////////////////////////////////////////////


...and here is the code to initilise the vertex buffer...

////////////////////////////////////////////////////////////////////////////
int _3DOBJECTS_init_buffers()
{
// Size of memory block
UINT size = 3 * (sizeof(CUSTOMVERTEX));
DWORD usage = 0;


// Create the Vertex buffer
cD3D.lpd3ddevice->CreateVertexBuffer(size, usage, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &lineBuffer, NULL);

// Copy the data into the vertex buffer
VOID* lpBuffer;
lineBuffer->Lock(0, sizeof(vertices), (void**)&lpBuffer, 0);
memcpy(lpBuffer, vertices, sizeof(vertices));
lineBuffer->Unlock();


return TRUE;
}
////////////////////////////////////////////////////////////////////////////


...and this is the code for my overall rendering pipeline( the render2D() function is empty at this time )...

////////////////////////////////////////////////////////////////////////////
int render()
{
HRESULT hr;

// Clear the screen...
cD3D.lpd3ddevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(50,50,50), 1.0f, 0);

// Begin the scene for rendering...
cD3D.lpd3ddevice->BeginScene();

// NOTE: The 3D rendering is done first as the 2D is layered on top of it.

// Perform 3D logic
RENDER_3D();

// Perform 2D logic
RENDER_2D();

// Close the scene to end rendering
cD3D.lpd3ddevice->EndScene();

// Now that the rendering is finished - output the final picture!
cD3D.lpd3ddevice->Present(NULL, NULL, NULL, NULL);

return TRUE;
}
//////////////////////////////////////////////////////////////////////////////


...and this is the code for rendering the triangles...

////////////////////////////////////////////////////////////////////////////////int RENDER_3D()
{
HRESULT hr;

// Render the Vertices
cD3D.lpd3ddevice->SetStreamSource(0, lineBuffer, 0, sizeof(CUSTOMVERTEX));
cD3D.lpd3ddevice->SetFVF( D3DFVF_CUSTOMVERTEX );
cD3D.lpd3ddevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );


return TRUE;
}
/////////////////////////////////////////////////////////////////////////////


...and there you have it. the "cD3D" is a class that basically initialises Direct3D etc - its a bit long winded but its worked on all of my other applications.

I'll try to upload a screen shot in a moment, but its basical

EDIT: Please use 'source' tags!

[Edited by - jollyjeffers on January 29, 2006 8:21:16 AM]

Share this post


Link to post
Share on other sites
Re: Nik02.

Funny you should mention that - I had a line that enabled the "auto-depth-stencil" in the Present Parameters...once commented out and executed the triangle appears...

Although I'm scratching my head as to why removing this statement from my other programs causes strange screen effects, at least I now know where the problem lies...

Thanks to all who dropped by! ^_^

Share this post


Link to post
Share on other sites
If you don't clear the depth buffer at some point, it likely contains the video memory that was in it's memory area at the time of it's allocation. In effect, this means that it contains "random" depth values and if you render something against it, arbitrary pixels get depth-rejected due to said "random" depth values.

So, if you have a depth buffer, be sure to clear it at least once (usually at least once every frame, in practice). If you don't have it, on the other hand, the Clear method results in a runtime error when asked to clear the depth.

If you do want to use a depth buffer, here's to clear it along with the color buffer:

cD3D.lpd3ddevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(50,50,50), 1.0f, 0);

Share this post


Link to post
Share on other sites

This topic is 4337 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this