Is it possible to get the pixel color?

Hi,

This is my first time that I’m using OpenGL in C++ I learned some basic stuff like drawing lines,points,polygons etc. and still learning.

I want to make a simple app that will detect color of the current pixel by specifying X and Y coordinates of the screen.
I’m using Windows and Dev-C++.
So if it is possible please give me function name or give me an example!

Thanks in advance!

I believe you are looking for glReadPixels.

Patrick

Yes, thanks pjcozzi

but sorry for bothering how can I get RGB value like 1.0,0.0,1.0 or something similar so I can determine if that is the wanted color
I used this code and It shows only 0

float col;
glReadPixels(1,EKRAN_VISINA - 40,1,1,GL_RGB,GL_FLOAT,&col);
cout << “COLOR:” << col << endl;

You can try using an unsigned char array of 3 bytes.
unsigned char pick_col[3]
glReadPixels(x , y , 1 , 1 , GL_RGB , GL_UNSIGNED_BYTE , pick_col);

Now pick_col is the array…

Here the values range from 0-255.So u can define floating point nos which can hold the values in range of 0 - 1

ie float r,g,b;
r = pick_col[0]/255.0;
g = pick_col[1]/255.0;
b = pick_col[2]/255.0;

Hope i answer your question.