If you do not want to use a second occlusion request session, you can try sampling the Z buffer to compare with your test point.
Since you are adding text next to a point, take the normalized value of the Z-buffer (say, using gluProject) of the point, and then compare this value with the selected Z-buffer (using the value of glReadPixels) at that point. If your point is beyond the (large) depth value that you have selected, your point should be closed, and you may not draw text.
This, of course, requires that you display all your geometry in front of the text, but that should not be a problem.
Code example:
// Assumed to already hold 3D coordinates of point GLdouble point3DX, point3DY, point3DZ; // Project 3D point coordinates to 2D GLdouble point2DX, point2DY, point2DZ; // 2D coordinates of point gluProject( point3DX, point3DY, point3DZ, mMatrix, pMatrix, vMatrix, // MVP matrices &point2DX, &point2DY, &point2DZ); // Read depth buffer at 2D coordinates obtained from above GLfloat bufDepth = 0.0; glReadPixels( static_cast<GLint>( point2DX ), static_cast<GLint>( point2DY ), // Cast 2D coordinates to GLint 1, 1, // Reading one pixel GL_DEPTH_COMPONENT, GL_FLOAT, &bufDepth); // Compare depth from buffer to 2D coordinate "depth" GLdouble EPSILON = 0.0001; // Define your own epsilon if (fabs(bufDepth - point2DZ) < EPSILON) // 3D point is not occluded else // 3D point is occluded by something
source share