Wstęp OpenGL: podstawy z użyciem C OpenGL SDKOpenGL SDK
Przykład // http://stackoverflow.com/questions/8000921/how-to-get-color-from-the-pixel-opengl // g++ r.cpp -lGL -lGLU -lglut -Wall // ./a.out
# include # include
using namespace std;
void display() { glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-10, 10, -10, 10, -1, 1);
glMatrixMode(GL_MODELVIEW); glLoadIdentity();
glPushMatrix(); glScalef(5,5,5); glBegin(GL_TRIANGLES); glColor3ub(255,0,0); glVertex2f(-1,-1); glColor3ub(0,255,0); glVertex2f(1,-1); glColor3ub(0,0,255); glVertex2f(1,1); glEnd(); glPopMatrix();
glutSwapBuffers(); }
void motion(int x, int y) { y = glutGet( GLUT_WINDOW_HEIGHT ) - y;
unsigned char pixel; glReadPixels(x, y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, pixel); cout << "R: " << (int)pixel << endl; cout << "G: " << (int)pixel << endl; cout << "B: " << (int)pixel << endl; cout << endl; }
int main(int argc, char **argv) { glutInitWindowSize(640,480); glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE); glutCreateWindow("glReadPixels()");
glutDisplayFunc(display); glutPassiveMotionFunc(motion); glutMainLoop(); return 0; }
Źródła