I just would like to add that it does not matter if modelMatrix, projMatrix and viewport variables of gluUnProject are declared as var or const. But removing even one of those modifiers causes program to crush on win32 (XP). I tested it on FPC 2.0.2 and 2.0.4 with and without Lasarus (0.9.14).