EACam
Warrior
154 Posts |
Posted - Jun 14 2004 : 11:18:42 PM
|
Just a quick question.
What's a Z-Buffer for? I think I have an idea, but I'm making a 2D game. Does a Z-Buffer have any application in a 2D game? If so, how, and how can I utilize it?
Thanks. |
|
Sr. Guapo
Swordmaster
USA
272 Posts |
Posted - Jun 15 2004 : 12:16:43 AM
|
A z-buffer basically stores depth information for each pixel. That way, the order that you draw things does not affect the order they are "layered". Without a depth buffer, the last thing you drew would be the furthest up (it would overlap everything). With a depth buffer, it would depend on the various depths of the objects as to which was on top.
The nice thing about depth buffer is they are VERY easy to use. Just use these three lines:
D3DWindow.EnableAutoDepthStencil = 1 D3DWindow.AutoDepthStencilFormat = D3DFMT_D16 D3DDevice.SetRenderState D3DRS_ZENABLE, 1
after initialising the device, and voila, the graphics card does the rest. I am pretty sure they can be used in 2D (though I am not 100%). It would make sense that they could, or the z-value on vertices would be pointless. It would definately make rendering much easier...
|
|
|
game_maker
Knave
Saudi Arabia
83 Posts |
Posted - Jun 15 2004 : 02:26:44 AM
|
as Sr. Guapo said you can use z values to layer your sprites instead of a loop,,, thats means you can draw sprite A before Sprite B and keeping Sprite A above B using z sorting values
I remeber once I was stack in a problem :
How Can you control the apearance of a sprite behind or above 3D Objects ,,, I changed the z value to 1 |
Edited by - game_maker on Jun 15 2004 02:43:33 AM |
|
|
EACam
Warrior
154 Posts |
Posted - Jun 15 2004 : 2:24:19 PM
|
Cool...I'll try to use it in my 2D game and see what happens. But, doesn't a stencil buffer limit my audience? I mean, i've heard that not ALL adapters have the capabilities. So would using it be a limiting factor in my game?
P.S. I currently have only the ZENABLE line in my init, but not the first 2, and I clear the Z-Buffer every frame, but I don't actually use it, as far as i know. |
|
|
VBBR
Moderator
Brazil
617 Posts |
Posted - Jun 15 2004 : 7:02:06 PM
|
Well I think you CAN use a Z-Buffer while NOT needing to use a stencil buffer. Better to do some research on this. (I don't know clearly what a stencil buffer is, anyway ) |
Whatever. Who knows... |
|
|
Sr. Guapo
Swordmaster
USA
272 Posts |
Posted - Jun 15 2004 : 9:04:21 PM
|
Yes, I always use a Z-Buffer, but I have never used a stencil buffer. I think I know what they could be used for, but I've never needed one... |
Edited by - Sr. Guapo on Jun 15 2004 9:04:44 PM |
|
|
Almar
Moderator
Netherlands
192 Posts |
Posted - Jun 17 2004 : 07:09:33 AM
|
I've never used a Z-buffer. I might use one in my next game I guess. This is the first time I actually read it's 100% possible in DG... :)
|
|
|
VBBR
Moderator
Brazil
617 Posts |
Posted - Jun 17 2004 : 10:50:49 AM
|
What is "DG"? Sorry for my dumbness... |
Whatever. Who knows... |
|
|
Sr. Guapo
Swordmaster
USA
272 Posts |
Posted - Jun 17 2004 : 11:08:50 AM
|
I was kinda wondering that also... . Is it direct Graphics maybe? Z-Buffers are very helpful. They are extremely easy to use and almost EVERY card can support them (including my ancient Voodoo3). They make rendering much easier by letting you draw ojects in any order, though they still are correct (You should still group objects though, less "SetRenderState" or SetTexture" calls = faster loop). |
|
|
VBBR
Moderator
Brazil
617 Posts |
Posted - Jun 17 2004 : 1:18:52 PM
|
Just imagine 3D graphics without Z-Buffers! Cheers to the guy who created them! |
Whatever. Who knows... |
|
|
Almar
Moderator
Netherlands
192 Posts |
Posted - Jun 17 2004 : 4:01:55 PM
|
DirectGraphics yes, just like D3D is Direct3D, D3DIM = direct 3d Immediate mode, D3DRM = Direct 3d retained mode |
|
|
VBBR
Moderator
Brazil
617 Posts |
Posted - Jun 17 2004 : 5:19:13 PM
|
See, I'm not really into this immediate mode and retained mode stuff, I'm from the DirectX8-DirectX9 era |
Whatever. Who knows... |
|
|
Sr. Guapo
Swordmaster
USA
272 Posts |
Posted - Jun 17 2004 : 9:10:37 PM
|
Same here... As far as I know, RM is easier, but not high quality, and IM is harder, but can look much better and support more features. I don't think I want to know anymore though, it almost seems like a step back... |
Edited by - Sr. Guapo on Jun 17 2004 9:11:15 PM |
|
|