#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 void init (void) { int i; GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 }; glClearColor (0.0, 0.0, 0.0, 1.0); glColor4fv (white); glDisable (GL_DITHER); } static void drawbox (GLfloat left, GLfloat right, GLfloat top, GLfloat btm, GLfloat z) { glBegin (GL_POLYGON); glVertex3f (left, top, z); glVertex3f (right, top, z); glVertex3f (right, btm, z); glVertex3f (left, btm, z); glEnd (); } #define START_QUERY(id)\ glBeginQueryARB(GL_SAMPLES_PASSED_ARB, id); #define TERM_QUERY()\ glEndQueryARB(GL_SAMPLES_PASSED_ARB);\ static void test (void) { int i, j; GLuint texName; GLuint queryId; int samples; int ready; glClear (GL_COLOR_BUFFER_BIT); glEnable (GL_DEPTH_TEST); glGenQueriesARB (1, &queryId); if (queryId <= 0) return; glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_PROJECTION); glPushMatrix (); glLoadIdentity (); glOrtho (-1.0, 1.0, -1.0, 1.0, 0.0, 25.0); glDepthMask (GL_TRUE); glColor3f (0.0, 1.0, 0); drawbox (-0.6, 0.6, 0.6, -0.6, -2.0); glDepthMask (GL_FALSE); glColor3f (0, 0, 1); START_QUERY (queryId); drawbox (-0.3, 0.3, 0.3, -0.3, -1.0); TERM_QUERY (); do { glGetQueryObjectivARB (queryId, GL_QUERY_RESULT_AVAILABLE_ARB, &ready); } while (!ready); glGetQueryObjectuivARB (queryId, GL_QUERY_RESULT_ARB, &samples); printf ("number of samples passed depth test = %d\n", samples); printf ("should be 900\n"); glFlush (); } void display (void) { glMatrixMode (GL_PROJECTION); glLoadIdentity (); test (); } int main (int argc, char **argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize (WINDSIZEX, WINDSIZEY); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc (display); glutMainLoop (); return 0; }