#include #include #include #include #define PIXEL_COLOR 0.6 GLfloat normal[3], position[4], direction[3]; void init(void) { GLfloat buf[4]; glClearColor(0.0, 0.0, 0.0, 0.0); glDisable(GL_DITHER); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); // Setup polymode and twoSided switch. glPolygonMode (GL_FRONT_AND_BACK, GL_POINT); glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); // Setup light position. position[0] = 0.0; position[1] = 0.0; position[2] = 1.0; position[3] = 0.0; glLightfv(GL_LIGHT0, GL_POSITION, position); // glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 1); buf[0] = 0.0; buf[1] = 0.0; buf[2] = 0.0; buf[3] = 1.0; glMaterialfv(GL_FRONT, GL_AMBIENT, buf); glMaterialfv(GL_FRONT, GL_DIFFUSE, buf); buf[0] = 1.0; buf[1] = 0.0; buf[2] = 0.0; buf[3] = 1.0; glMaterialfv(GL_FRONT, GL_SPECULAR, buf); glMaterialf(GL_FRONT, GL_SHININESS, 1.0); buf[0] = 1.0; buf[1] = 1.0; buf[2] = 1.0; buf[3] = 1.0; glLightfv(GL_LIGHT0, GL_SPECULAR, buf); glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); } static void test(void) { normal[0] = 0; normal[1] = -1/sqrt(2); normal[2] = 1/sqrt(2); glNormal3fv(normal); glBegin(GL_POINTS); glVertex2f(9.5, 0.5); glEnd(); } void display(void) { GLfloat buf[3]; GLfloat expected; glViewport(0, 0, 10, 10); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, 10, 0, 10); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); test(); glReadPixels(9, 0, 1, 1, GL_RGB, GL_FLOAT, (GLvoid *)buf); expected = (0.5/10 + 1)/2; printf ("actual buf[0]: %f, expected: %f\n", buf[0], expected); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(10, 10); glutInitWindowPosition(20, 20); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }