Sign in to follow this  
Phy

Read ZBuffer

Recommended Posts

Is there a way to read from the zbuffer? I'm trying to do pointsprite visibility testing for a neato effect, but can't find anyway to do it.

Share this post


Link to post
Share on other sites
You can get the screen coordinates by multiplying the vertex by the ModelviewProjection matrix. To obtain the transformed z position of your vertex, multiply the vertex by the Modelview matrix.

z position makes no sense when considering screen coordinates.

Share this post


Link to post
Share on other sites

float mtx[16];
glGetFloatv( GL_MODELVIEW_MATRIX, mtx );
tpos[0] = mtx[0]*ptcl->pos[0] + mtx[1]*ptcl->pos[1] + mtx[2]*ptcl->pos[2] + mtx[3];
tpos[1] = mtx[4]*ptcl->pos[0] + mtx[5]*ptcl->pos[1] + mtx[6]*ptcl->pos[2] + mtx[7];
tpos[2] = mtx[8]*ptcl->pos[0] + mtx[9]*ptcl->pos[1] + mtx[10]*ptcl->pos[2] + mtx[11];
glGetFloatv( GL_PROJECTION_MATRIX, mtx );
tpos[0] = mtx[0]*tpos[0] + mtx[1]*tpos[1] + mtx[2]*tpos[2] + mtx[3];
tpos[1] = mtx[4]*tpos[0] + mtx[5]*tpos[1] + mtx[6]*tpos[2] + mtx[7];
tpos[2] = mtx[8]*tpos[0] + mtx[9]*tpos[1] + mtx[10]*tpos[2] + mtx[11];

float fBuffValue;
glReadPixels( tpos[0], tpos[1], 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &fBuffValue );

if ( fBuffValue < tpos[2] )
ptcl = ptcl->nextParticle;



good thing you can 'try' and edit other peoples posts =)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this