Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


[Solved] IDirect3DDevice9::Clear error


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Kai_Jackson   Members   -  Reputation: 105

Like
0Likes
Like

Posted 30 January 2013 - 12:47 PM

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~


Sponsor:

#2 Khatharr   Crossbones+   -  Reputation: 3064

Like
2Likes
Like

Posted 30 January 2013 - 01:04 PM

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)


Edited by Khatharr, 30 January 2013 - 01:06 PM.

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.

#3 Kai_Jackson   Members   -  Reputation: 105

Like
0Likes
Like

Posted 30 January 2013 - 01:22 PM

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~


#4 Endurion   Crossbones+   -  Reputation: 3693

Like
0Likes
Like

Posted 30 January 2013 - 11:51 PM

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>

#5 Khatharr   Crossbones+   -  Reputation: 3064

Like
0Likes
Like

Posted 31 January 2013 - 05:03 AM

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


Edited by Khatharr, 31 January 2013 - 05:07 AM.

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS