PDA

View Full Version : Is it possible to get the pixel color?



Nikola Vitanovic
04-13-2010, 02:52 PM
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!

pjcozzi
04-13-2010, 02:56 PM
I believe you are looking for glReadPixels (http://www.opengl.org/sdk/docs/man/xhtml/glReadPixels.xml).

Patrick

Nikola Vitanovic
04-13-2010, 03:17 PM
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;

Mukund
04-13-2010, 03:24 PM
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.