[Solved] IDirect3DDevice9::Clear error

Started by
3 comments, last by Khatharr 11 years, 2 months ago

I've been learning DirectX over the last few days, and I seem to be having a problem with the Clear method for clearing the backbuffer:


bool Draw()
{
	//clear the scene
	if (d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB(0, 0, 100), 1.0f, 0) == D3DERR_INVALIDCALL)
		return false;

	d3ddev->ColorFill(backbuffer, NULL, D3DCOLOR_XRGB(0, 0, 100));
	...
        return true;
}

d3ddev is of type LPDIRECT3DDEVICE9 and otherwise works fine - if I comment out the d3d->Clear(...) line the rest will function as intended, no other issues elsewhere in the code (ColorFill will run and fill the screen dark blue, which seems to achieve the same effect). Curious as to why Clear doesn't work though. Any ideas?

~stay curious~

Advertisement

Are you sure you have a zbuffer attached?

http://msdn.microsoft.com/en-us/library/windows/desktop/bb174352%28v=vs.85%29.aspx

I recall it misbehaving but I can't remember what I did to fix it. Is that fill there because it's not working or are you intending to do both? (that would be silly)

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

I put the ColorFill in there as a test, it would indeed be silly to do both!

I removed D3DCLEAR_ZBUFFER and it works now. I'll be honest, I don't actually know what a zbuffer is at this point. I'm sure I'll revisit this code in a week or two and think "oh, well duh" but for now I'm content that it works. Thanks!

~stay curious~

If you check a return value from a DirectX function, always use the FAILED or SUCCEEDED macro!

There are a lot more error codes than that single one. And there's a few border cases when there's more than one success value.

A z buffer is basically a buffer with a depth value for every pixel. Quite important if you go real 3d and objects overlap. Every single pixel will be depth checked.

Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>

If you have a zbuffer (aka depth buffer) then whenever you render something the following steps are taken on a per-pixel basis:


new_z = //z value for this pixel based on what you're rendering
depth_z = //z value for that pixel in the zbuffer
if(depth_z > new_z) { //this test is configurable - it's called the 'depth test' (see MSDN)
  depth_z = new_z
  pixel_color = new_pixel_color
}
else {
  //skip to next pixel
}

Unless you're doing some special effects with the buffer you typically want to clear it every frame before drawing. The common use is simply to make sure that if you draw something and then draw another thing that overlaps the same pixels the correct pixel colors will be 'on top'.

http://en.wikipedia.org/wiki/Z-buffering

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

This topic is closed to new replies.

Advertisement