Read ZBuffer
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.
Kind of a newbie question, but how do I convert vertex coordinates to screen coordinates and a z value?
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.
z position makes no sense when considering screen coordinates.
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 =)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement