Hello,
I try to implement an efficient lens flare, and to do that I need to add an occlusion test. So after some researches, I have chosen to use occlusion queries to make this test.
There is my implementation :
GLuint a = 0;
GLuint result = 0;
// Create queries
glGenQueries(1, &a);
glDepthMask(GL_FALSE);
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
// Launch Queries
glBeginQuery(GL_SAMPLES_PASSED, a);
// Draw sun flare
glBegin(GL_QUADS);
glVertex3f(p.x - 258, p.y - 258, p.z);
glVertex3f(p.x + 258, p.y - 258, p.z);
glVertex3f(p.x + 258, p.y + 258,p.z);
glVertex3f(p.x - 258, p.y + 258, p.z);
glEnd();
glEndQuery(GL_SAMPLES_PASSED);
glGetQueryObjectuiv(a, GL_QUERY_RESULT, &result);
glDepthMask(GL_TRUE);
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
The implementation seems good but the result is very strange. Indeed, when I draw an object in front of my lens flare, if this one is not far enough, the occlusion test is successful.
For example, if the current object is drawn at a Z-position of 0 and the sun flare is drawn at a Z-position of -1000. The test is positive, but if the sun flare is drawn at a Z-position of -10000, the test is negative as it should be.
Someone can find an answer to this problem?
Thanks by advance.