# DrawPrimitive: Triangle is missing pixels?

This topic is 4704 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Could we see a screenshot?

##### Share on other sites
As well as the initialization and rendering code.

##### 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-&gt;CreateVertexBuffer(size, usage, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &lineBuffer, NULL);	// Copy the data into the vertex buffer	VOID* lpBuffer;	lineBuffer-&gt;Lock(0, sizeof(vertices), (void**)&lpBuffer, 0);	memcpy(lpBuffer, vertices, sizeof(vertices));	lineBuffer-&gt;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-&gt;Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(50,50,50), 1.0f, 0);	// Begin the scene for rendering...	cD3D.lpd3ddevice-&gt;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-&gt;EndScene();	// Now that the rendering is finished - output the final picture!	cD3D.lpd3ddevice-&gt;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-&gt;SetStreamSource(0, lineBuffer, 0, sizeof(CUSTOMVERTEX));	cD3D.lpd3ddevice-&gt;SetFVF( D3DFVF_CUSTOMVERTEX );	cD3D.lpd3ddevice-&gt;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

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

##### Share on other sites
Clear the depth buffer also, if you have one [smile]

##### 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 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);

1. 1
2. 2
Rutin
21
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013601
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!