PDA

View Full Version : glReadPixels will beat me without your help !!!



Bra'Tac
05-04-2001, 04:28 AM
Hi.
I want to use glReadPixels to selected an object on the screen.
My drawObjects function draw my objects with a red variant depending of their id. So I want to catch the color in the backbuffer to be able to know on which object I have clicked. I know that this is a common method but I have not be able to make it work. Here is a portion of code, the problem is that "pixels_data" always stay at 1, wherever I click.

GLfloat pixels_data;

glDisable(GL_TEXTURE_2D);
drawObjects_SelectionMode();
glReadBuffer(GL_BACK);
glReadPixels(mouse_pos.x,mouse_pos.y,1,1,GL_RED,GL _FLOAT,&pixels_data);
glEnable(GL_TEXTURE_2D);


Any comments,sugestion,idea ????

zed
05-04-2001, 02:45 PM
not really the best method but
well use GL_UNSIGNED_BYTE instead of GL_FLOAT.
also youll be limited to 256 different objects.
also is dithering disabled

Cardinal
05-07-2001, 11:58 AM
first: did you transform the winblows coordinates to opengl windows coordinates? the y is opposite, so mouse.y == ClientHeight-y;

try switching to drawobject_pickmode to your main render function, to make sure it is drawing correctly... then check to make your mouse is where you think it is by using unproject/draw point.