I have the impression that you want to click on the vertices of the OGL model, "nodes" in your words, right? In this case, since there are only a few nodes you could iterate over the nodes, calculate the screen point and compare with the click position (and allow for some tolerance). Calculation of the screen point can be done by the inverse of your gluUnproject: gluProject

type

TOpenGLPoint = record

X, Y, Z: GLDouble;

end;

function CalcOpenGLScreenPoint(P: TOpenGLPoint): TPoint;

var

viewport: array[0..3] of Integer;

modelview: array[0..15] of GLDouble;

projection: array[0..15] of GLDouble;

X,Y,Z: Double;

begin

glGetDoublev(GL_MODELVIEW_MATRIX, @modelview );

glGetDoublev(GL_PROJECTION_MATRIX, @projection );

glGetIntegerv(GL_VIEWPORT, @viewport);

gluProject(P.X, P.Y, P.Z, @modelView, @projection, @viewport, @X, @Y, @Z);

Result.X := round(X);

Result.Y := viewport[3] - round(Y);

end;

function TForm1.FindClickedNodeIndex(X, Y: Integer): Integer;

// Assuming that your model consists of an array of vertices (TOpenGLPoint)

const

Tolerance = 5;

var

i: Integer;

P: TPoint;

begin

for i := 0 to Length(Vertices)-1 do

begin

P := CalcOpenGLScreenPoint(Vertices[i]);

if (abs(P.X - X) < Tolerance)) and (abs(P.Y - Y) < Tolerance) then

begin

Result := i;

exit;

end;

end;

Result := -1;

end;

Attaching a small OpenGL project which demonstrates this. The nodes in the demo are at the corners/endpoints of the table-like object. Ctrl-click on them and the coordinates of the clicked vertex (in model coordinates) will be displayed in the blue label at the bottom.

P.S. Sorry for mentioning the integer issue in my previous post, I was just confused by the different order of declarations and procedure calls.