#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 void init(void) { glDisable(GL_DITHER); } static void test(void) { unsigned char buf[4]; unsigned char destColor[] = { 34, 45, 56}, srcColor[] = {23, 34, 45}; GLfloat x = 2, y = 2; GLubyte bitmap[] ={0xff, 0xff}; glColor3ubv(destColor); glBegin(GL_POINTS); glVertex2f(x, y); glEnd(); glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_CLEAR); //AND); glColor3ubv(srcColor); glRasterPos2f(x, y); glBitmap(1, 1, 0, 0, 0, 0, bitmap); /* glBegin(GL_POINTS); glVertex2f(x, y); glEnd(); */ glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, buf); printf("draw pixel at (2, 2): %d %d %d\n", buf[0], buf[1], buf[2]); } 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); glutInitWindowSize(WINDSIZEX, WINDSIZEY); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }