DrawPrimitive: Triangle is missing pixels?

Started by
5 comments, last by Nik02 18 years, 2 months ago
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...

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

Advertisement
Could we see a screenshot?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
As well as the initialization and rendering code.
Sean Henley [C++ Tutor]Rensselaer Polytechnic Institute
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]

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

Clear the depth buffer also, if you have one [smile]

Niko Suni

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! ^_^

Languages; C, Java. Platforms: Android, Oculus Go, ZX Spectrum, Megadrive.

Website: Mega-Gen Garage

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

Niko Suni

This topic is closed to new replies.

Advertisement