Hi all, I use the ScreenToWorld method (below) like so:
Method using code
Code:
Begin
{...}
p0 := ScreenToWorld(FMousePosX,FMousePosY,0);
p1 := ScreenToWorld(FMousePosX,FMousePosY,1);
{...}
End;
Method being used
Code:
Function TAbaloneGL.ScreenToWorld(AScreenX, AScreenY, AScreenZ : GLdouble) : TVector3f;
Var
Viewport : TViewPortArray;
MVMat : T16dArray;
PJMat : T16dArray;
ObjX : GLdouble;
ObjY : GLdouble;
ObjZ : GLdouble;
Begin
// Retrieves the viewport
glGetIntegerv(GL_VIEWPORT, @Viewport);
// Retrieve the matrices
glGetDoublev(GL_MODELVIEW_MATRIX, @MVMat[0]);
glGetDoublev(GL_PROJECTION_MATRIX, @PJMat[0]);
// Unproject screen coordinates
gluUnProject(
AScreenX,
Viewport[3] - AScreenY,
AScreenZ,
MVMat, PJMat, Viewport,
@ObjX, @ObjY, @ObjZ);
Result := V3(ObjX, ObjY, ObjZ);
End;
This works just find under Delphi 5 without any issues, but when I compile and run it using Lazarus (latest version 0.9.1, it crashes on the gluUnProject line with an access violation
If I run it through the debugger it gives this error:
"Project raised exception class 'External: SIGSEGV"
I can't seem to figure it out...
PS I am using the GL.pas and GLU.pas files that come with JEDI-SDL if that helps...
cheers,
Paul.
Bookmarks