Jump to content
  • Advertisement
Sign in to follow this  
Phy

Read ZBuffer

This topic is 4836 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
Kind of a newbie question, but how do I convert vertex coordinates to screen coordinates and a z value?

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
I can't get the values to work right, whats the tag for code and I'll post it here?

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!