View Full Version : Color Buffer
06-29-2002, 09:01 AM
Is there a way to clear some part of the buffer? I do not mean the glscissor. Suppose I have two objects A and B, and I want to clear the buffer such that A remains but B is erased. I do not want to clear all the buffer and redraw A.
If you could clarify it with example code, I would be glad.
06-29-2002, 10:26 AM
Why not render flat triangles or quads (with the required clear color, no textures, no lighting and no depth test) that wipe out the region you want leaving the rest untouched.
This would act like a mask, as well the mask does not have to be static, it can move around the screen and even change size.
If you needed the depth buffer cleared as well then you could render the same primitives but now contain the clear depth desired and you set the dpeth test to always pass.
06-29-2002, 10:29 AM
I assumed object A and B have primitive shapes (triangle, square, regular polygon etc.). If these objects have arbitrary shapes then you need to provide more detail because I think there is a way to solve your problem but I am not clear exactly what kind of objects you want have.
06-29-2002, 10:39 AM
It is not important what kind of object is used. I'm sorry, I couldn't explain the problem.
Suppose in the init function I draw A and B and they take the form:
| AAAA |
| AAACB |
| AACCBB |
| ACCCBBB |
Here C is the intersection of A and B (it doesn't matter if A or B is clipped).
Then when I call the display function, it sould erase only the B (and probably draw another objects like D) and obtain
| AAAA |
| AACCDDDD |
| AACCDDDD |
| AAAA |
(C is the intersection of A and D).
I want that the display function erases the B object without erasing A (it may erase the intersection, but it would be better if it don't).
Maybe this is impossible but I think the solution lies in the buffer operations.
06-29-2002, 11:08 AM
You can use the stencil buffer to do exactly this. I don't know, where for you need this exactly, but following way you can do it:
disable stencil test, enable stencil write
fill the stencil buffer with zero, set the stencil func to ADD and all conditions to always.
draw a with a stencil value of 1
draw b with a stencil value of 2
In the intersection area 3 will be the result, if you use ADD as stencil function. Where only A was drawn it will be 1, where B was drawn 2. Then enable stencil test and disable stencil write and set the conditions to EQUAL 3, so you can exactly render to the region of the intersection/of A/of B.
Using stencil is very simple, simply search for glStencil on this forum or search for "stencil shadows" and you should find a bunch of detailed information how to use it. But I think this is exactly, what you need.
p.s. If your program shall run in 16 bit as well, you can use a pbuffer with stencil for doing this. Stencil is else only available in 32 bit colordepth!
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.