PDA

View Full Version : Clipping planes and 3d Quadrics. Filling



Clayton
07-22-2003, 12:13 PM
I need to be able to fill a Sphere, (Drawn Quadric Style) so that when it is clipped by a plane the inside of the Sphere is Solid instead of as an outline. Does anyone have any ideas on how to accomplish this?

errno
07-22-2003, 10:30 PM
check out the red book, there is an example on capping clipped convex objects (in frame buffer/stencil).

the idea is to draw your clipped object, with stencil test enabled, with these options:
glStencilFunc(GL_ALWAYS, 0x1, ~0);
glStencilOp (GL_REPLACE, GL_REPLACE, GL_INVERT);
then draw a big quad which cover the screen (using ortho projection, it's simplier) with these stencil options:
glStencilFunc(GL_EQUAL, 0x1, ~0);
glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);

if cull face is enabled, you ave to change the stencil params.

Clayton
07-23-2003, 07:26 AM
I've got all of the stencil test loading things done inside the drawing. But I'm not quite sure how to get the Quad drawn. I'm working with a very dynamic camera system, and when I draw the Quadralateral, despite me setting the Orthoganal viewpoint, it still draws in perspective as opposed to across the screen. By the way, what page of the red book has an example of capping? I found a section on it, but it was just a short blurb on page 446 chapter 10.

[This message has been edited by Clayton (edited 07-23-2003).]

Clayton
07-23-2003, 10:21 AM
Please Note that I'm using QT and as such have not access to glut or Windows Specific Functions.

errno
07-23-2003, 10:38 PM
to draw the quad:
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
draw the quad (-1,-1) (1,-1) (1,1) (-1,1)
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);


I found the example here: http://fly.cc.fer.hr/~unreal/theredbook/chapter10.html
it's just before the depth test chapter. this is not an example, just a little how-to.

Clayton
07-24-2003, 08:25 AM
I've actually got everything in right it looks like, but It's still being rather stubborn. Here's the code (Note that the reason that I draw the quad in this function and not outside is that I'm drawing Lots of different colored spheres.

void drawSphere( const Point &center, const double radius, const QColor &color, int DrawQuality )
{
if(!(glIsEnabled(GL_STENCIL_TEST)))
{
glEnable(GL_STENCIL_TEST);
}
glEnable(GL_LIGHTING);
GLfloat TheColor[4] = { color.red()/255.0, color.green()/255.0, color.blue()/255.0 , 0} ;
glPushMatrix();
static GLUquadricObj* qobj = gluNewQuadric();
glTranslatef( center.x(), center.y(), center.z() );
glColor3f( color.red()/255.0, color.green()/255.0, color.blue()/255.0 );
glStencilFunc(GL_ALWAYS,0x1,~0);
glStencilOp(GL_REPLACE,GL_REPLACE,GL_INVERT);
gluSphere( qobj, radius,DrawQuality, DrawQuality );
glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glColor3f( color.red()/255.0, color.green()/255.0, color.blue()/255.0 );
glStencilFunc(GL_EQUAL,0x1,~0);
glStencilOp(GL_KEEP,GL_KEEP,GL_KEEP);
glBegin(GL_QUADS);
glVertex2f(-1.0,-1.0);
glVertex2f(1.0,-1.0);
glVertex2f(1.0,1.0);
glVertex2f(-1.0,1.0);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}

If you notice any glaring inconsistancies, it would be of great help. Thanks for all your help thus far.

Clayton
07-29-2003, 01:24 PM
Anybody got anything?