how to draw a half space?

Hi,friends,i need to draw a half space object, what i used is the glClipPlane function, but there is a problem, that i can not draw the cutting face of the object, what i have is the original object (extruded solid for example), and the para of the plane ( a point and a normal vector), i can not get the cutting face by the CAD algorithm, because i’ve never build the basic data structure as a CAD, my task is only for showing object.

If I understand you correctly, you want to render the cut face.

There are a couple of ways: 1 is to render a poly that exatly represents the cut face.
2. fake it by using a stencil buffer trick.

There is a demo on the

that shows #2 very well. I think the trick was to set stencil bits as you rendered back and front polys while color writing was off. Then reset stencil function and render a colored poly. For #1, I don’t remember seeing a publicly available algorithm.


Hi,V-man, thx a lot!i think i will use the Stencil to solve this problem. thanks again!

Here’s that sample code by the way.

-JasonM @ ATI

thanks again, and i’m doing it now, but the sequence of mine is:

  1. turn on the stencil test and disable depth test and depth mask.
  2. draw the back face of object and mark the passed pixel 1.
  3. draw the front face and mark the passed pixel 0.
  4. turn off the stencil test and draw the plane.

what i do will draw one more time of the overlap face of the object, but i think it will work in the case of when part of back face of the object be cut by other object(not pass the z test, because there still have some other object around), it’ll still can work.

sorry, there’s an error, the step 4 should be disable the cilpplane and enable the z-buffer test and mask, then draw the plane

It may not matter much if you have a simple scene, but drawing the front faces first will result in better performance due to heirarchical Z effects on modern chips.

    -JasonM @ ATI

i solve the halfspace problem, thx everybody very much!! and the halfspace of what i need to show is quite complicated, there are more than one half spaces needed to cut one object and i need to show every cutting face correctly, quite a headache thing, but whatever solved it now, feel very happy, but still have problem, that is when the size of my object is very small, the showing will have some gaps between each cutting face and is changing while i’m moving the object, i guess it’s caused by the tolerance of opengl halfspace cutting caculations, so i think if i can set the precision of the opengl system , it will be helpful. so does anybody know how to set the precision with opengl or any way to solve my problem?

and BTW,JasonM, what the difference with the hierarchical Z effects? and how does it work?thx.

opengl works with 32bit floats. no way to change it.
if you get precision problems you have to fix it on the cpu. (scaling the vertices before submitting them to opengl)

Problems could also be Z buffer fighting from too little Z precision or a “too near” Z near plane.

You can achieve a per-pixel accurate clipping plane by using a two-pixel texture, where one pixel maps to opaque and the other to transparent, and the appropriate linear TexGen set-up. Enable alpha testing, and you’re done. This is possibly more precise than, say, if the driver had to emulate clip planes with geometry modification in software.

Originally posted by AdrianD:
opengl works with 32bit floats. no way to change it.
if you get precision problems you have to fix it on the cpu. (scaling the vertices before submitting them to opengl)

To be more exact, GL requires a minimum precision of 10^(-5). GL doesn’t ask for any specific format even. Using 256 bit IEEE floats is entirely possible, but only the implementor can do that.


ok,i c that, thanks everybody! whatever i will try to find some other way to solve this problem