#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 void init(void) { glEnable(GL_DEPTH_TEST); glDepthFunc(GL_ALWAYS); } static void test(void) { GLfloat srcFloatPixels[32*32]; GLushort srcUShortPixels[32*32]; GLfloat results[32*32]; int i; glRasterPos2f(0.25, 0.25); for (i=0; i<1024; i++){ srcUShortPixels[i] = 61042; srcFloatPixels[i] = 61042.0 / 65536; } //glDrawPixels(32, 32, GL_DEPTH_COMPONENT, GL_FLOAT, srcFloatPixels); glDrawPixels(32, 32, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, srcUShortPixels); glDisable(GL_DEPTH_TEST); glReadPixels(0, 0, 32, 32, GL_DEPTH_COMPONENT, GL_FLOAT, results); for (i=0; i<1024; i++){ if (fabsf(results[i] - srcFloatPixels[i]) > 0.0001){ printf("result is %f, src is %f at %d\n", results[i], srcFloatPixels[i], i); exit(1); } } printf("PASS!\n"); exit(0); } void display(void) { glViewport(0, 0, WINDSIZEX, WINDSIZEY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, WINDSIZEX, 0, WINDSIZEY); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); test(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(WINDSIZEX, WINDSIZEY); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }