Javier Abadia Miranda (jabadia++at++sfe.indra.es)
Mon, 21 Jun 1999 15:12:00 +0200
> The sky dome consistes of a pfGeoSet with a pfGeoState which is
> attached to the scene graph. If I didn't need to worry about the sky dome I
> could move the far clip-plane closer (far =15-20 000). Could I somehow draw
> the sky geoset in a draw callback with depth testing disabled so that the
> sky would be in the background even if the far clip-plane is moved closer.
>
Try this:
int preCullDome(pfTraverser *trav, void *userData)
{
pfCullResult(PFIS_MAYBE | PFIS_TRUE | PFIS_ALL_IN);
return PFTRAV_CONT;
}
int preDrawDome(pfTraverser *trav, void *userData)
{
float m[16];
float c, d;
float far;
float near;
/* get current near and far */
pfGetChanNearFar(pfGetTravChan(trav), &near, &far);
/* put here the far value you need for the dome only */
far = 40000.0f;
/* get one copy of projection matrix */
glGetFloatv(GL_PROJECTION_MATRIX, m);
/* modify current projection matrix so that we change far */
/* value (see man glFrustum). NOTE: if any other value */
/* apart from far is changed, you need to modify more matrix */
/* elements */
c = (-far + near) / (far - near);
d = (-2 * far * near) / (far - near);
m[10] = c;
m[14] = d;
glPushAttrib(GL_TRANSFORM_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixf(m);
glPopAttrib();
/* sky dome is always furthest */
glDepthRange(1.0f, 1.0f);
glDepthFunc(GL_EQUAL);
return PFTRAV_CONT;
}
int postDrawDome(pfTraverser *trav, void *userData)
{
/* restore usual depth testing */
glDepthFunc(GL_LESS);
glDepthRange(0.0f, 1.0f);
/* restore previous projection matrix */
glPushAttrib(GL_TRANSFORM_BIT);
glMatrixMode(GL_PROJECTION_MATRIX);
glPopMatrix();
glPopAttrib();
return PFTRAV_CONT;
}
Please, comments to this code will be appreciated.
Bye.
-- Javier Abadia Miranda / Ingeniero en Informatica MADRID (SPAIN) / Especialista en Informatica Grafica
This archive was generated by hypermail 2.0b2 on Mon Jun 21 1999 - 06:15:03 PDT