PDA

View Full Version : What should I get with this code?



07-22-2002, 02:39 AM
GLfloat pixels[1][1];
glReadPixels(x,y,1,1,GL_RED,GL_FLOAT,pixels);
if(pixels[0][0]==(float)w) MessageBox("We have a customer !!");

x and y are the glCoordinates pointed by the mouse. Only problem is wherever I click, the value of the pixel still equals w....
What should be stored within pixels in my code?

MofuX
07-22-2002, 02:56 AM
i think your error is in glReadPixel...

you pass in a 2-dimensional array, but he only wants to write into a single varible (of FLOAT)

glReadPixel(x,y,1,1,GL_RED,GL_FLOAT,pixels[0][0]);

might be a solution for your problem

Robbo
07-22-2002, 03:13 AM
Erm - not sure about that above:

glReadPixel(x,y,1,1,GL_RED,GL_FLOAT,&pixels[0][0]);

or perhaps,

GLfloat Pixel;

glReadPixel (x,y,1,1,GL_RED,GL_FLOAT,&Pixel );

07-22-2002, 06:00 AM
I solved it.
The problem is OpenGL doesnt use OpenGL coordinate for this matter, but Viewport coordinate (aka x window coordinate, height - y coordinate).