Initializing stencil buffer

Started by
4 comments, last by Sneftel 21 years, 8 months ago
I''m making a 2D adventure game engine using DirectX 8, including character drawing using D3DXSprite on a prerendered 3D background. I was planning to use the stencil buffer for compositing the characters into the scene, so they would not be drawn in places where they were behind foreground scenery. But DirectX seems intent on not letting me initialize the stencil buffer except to a constant value: * CopyRects mentions that it won''t work with depth or stencil buffers * Lock also won''t work with stencil buffers How should I get the stencil data into the buffer to begin with? Don''t listen to me. I''ve had too much coffee.
Advertisement
Hey Sneftel,

Why do you need to use the stencil buffer? Couldn''t you get the same effect by rendering foreground and background images at different z-levels, with your character sprites somewhere in between?

--Hoozit.
----------------------Check out my game demo and resume at www.fivestory.com/projects/game.
quote:Original post by HoozitWhatzit
Hey Sneftel,

Why do you need to use the stencil buffer? Couldn''t you get the same effect by rendering foreground and background images at different z-levels, with your character sprites somewhere in between?

--Hoozit.


Because there may be more than just a foreground and a background; many scenes will have objects in the middle somewhere. I plan to use the stencil buffer in much the same way as the depth buffer, except that I won''t have to render geometry to get it.

Rendering dissolves using the depth buffer requires directly setting it; how is it done there?


Don''t listen to me. I''ve had too much coffee.
bump


Don''t listen to me. I''ve had too much coffee.
Well, there''s no way (That I know of) to get access to the stencil buffer memory.

However, if you''re looking for a dissolve effect, you can probably get by by using a D3DFMT_Z16_LOCKABLE backbuffer, clearing it to 1.0f, and then locking and setting pixels to 0.0f (closest).

My personal advice would be to simply stay away from the dissolves :D

I''d do stuff like fades, etc. But then, I''m moderately lazy

quote:Original post by Drilian
Well, there's no way (That I know of) to get access to the stencil buffer memory.

However, if you're looking for a dissolve effect, you can probably get by by using a D3DFMT_Z16_LOCKABLE backbuffer, clearing it to 1.0f, and then locking and setting pixels to 0.0f (closest).

My personal advice would be to simply stay away from the dissolves :D

I'd do stuff like fades, etc. But then, I'm moderately lazy



I have to assume there's a less hackish way to do it, tho. I mean, the DirectX documentation itself says:

quote:
You can define a series of stencil masks and copy them into the stencil buffer on successive frames. Alternately, you can define a base stencil mask for the first frame and alter it incrementally.


I downloaded a sample ATI application that does dissolving, using DX7. It was extremely simple there; just blit an image into the stencil buffer. I find it extremely hard to believe that MS would remove functionality like that, especially since they were trying to make D3D more versatile.


Don't listen to me. I've had too much coffee.

[edited by - sneftel on July 28, 2002 11:36:28 AM]

This topic is closed to new replies.

Advertisement