Don't know about reading pixels, but here is old function i have in libs that can be used to pick a specified object from OpenGL screen. It is pixel perfect, doesn't make a ray and is as fast as your RenderProc which renders single triangle or a full object on screen. You can do this test after or during flipping main screen and draw unflipped and without any textures and lighting.
Code:
type
TRenderProc = procedure(index: integer);
...
// Returns render index if cursor points it
// or -1 if no match
function MousePick(mx, my, PickRadius: double;
Count: integer; RenderProc: TRenderProc): integer;
var SelBuffer: array[0..511] of TGLUint;
i,hits: integer; viewport: TGLVectori4;
d1: double;
begin
result:=-1;
if count<1 then exit;
glGetIntegerv(GL_VIEWPORT,@viewPort);
glSelectBuffer(512, @SelBuffer);
glRenderMode(GL_SELECT);
glInitNames; glPushName(0);
glMatrixMode(GL_PROJECTION);
glPushMatrix; glLoadIdentity;
gluPickMatrix(mx,my,PickRadius,PickRadius,viewport);
gluPerspective(45, AspectRatio, TGL_NEARZ, TGL_FARZ);
glMatrixMode(GL_MODELVIEW);
for i:=0 to Count-1 do begin
glLoadName(i);
RenderProc(i);
end;
glMatrixMode(GL_PROJECTION);
glPopMatrix;
glMatrixMode(GL_MODELVIEW);
hits:=glRenderMode(GL_RENDER);
if hits>0 then begin
d1:=selBuffer[1]; result:=selBuffer[3];
for i:=1 to hits-1 do
if selBuffer[i*4+1]<d1 then begin
result:=selBuffer[i*4+3]; d1:=selBuffer[i*4+1];
end;
end;
end;
Bookmarks