Results 1 to 3 of 3

Thread: gluUnproject

  1. #1

    gluUnproject

    Hi, i've spotted this code around:
    [pascal]
    {------------------------------------------------------------------}
    { Get the vector for the current mouse position }
    {------------------------------------------------------------------}
    function GetOpenGLPos(X, Y: Integer): TVector;
    var
    viewport: TViewPortArray;
    modelview: T16dArray;
    projection: T16dArray;
    winZ,winY: Single;
    begin
    glGetDoublev(GL_MODELVIEW_MATRIX, @modelview[0] ); // Get the Current Modelview matrix
    glGetDoublev(GL_PROJECTION_MATRIX, @projection[0] ); // Get the Current Projection Matrix
    glGetIntegerv(GL_VIEWPORT, @viewport[0] ); // Get the Current Viewport

    winY := viewport[3] - y; //Change from Window to OpenGL coordinate system

    glReadPixels(X, Round(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, @winZ );//Read the Depth value at the current X and Y position
    gluUnProject(X, winY, winz, modelview, projection, viewport, // Get the vector for the current mouse position
    @(Result.x), @(Result.y), @(Result.z)); // And Return it from the function
    end;
    [/pascal]

    But it gives AV when i run it..
    Any of you is using gluUnproject ? Thanks.
    This picking stuff is driving me mad
    If you save your data in a proprietary format, the owner of the format owns your data.
    <br /><A href="http://msx80.blogspot.com">http://msx80.blogspot.com</A>

  2. #2

    gluUnproject

    Where does the AV happen? Can you post a simple project that shows the AV?
    <br /><br />There are a lot of people who are dead while they are still alive. I want to be alive until the day I die.<br />-= Paulo Coelho =-

  3. #3

    gluUnproject

    This is how I use gluUnproject:
    [pascal]
    type
    T3D_Point = Array[0..2] of gldouble;
    function GetWorldPos(X,Y: integer):T3D_Point;
    var
    viewport: TViewPortArray;
    modelview: T16dArray;
    projection: T16dArray;
    winZ: single;
    resPoint: T3D_Point;
    begin
    glGetDoublev(GL_MODELVIEW_MATRIX,@modelview);
    glGetDoublev(GL_PROJECTION_MATRIX,@projection);
    glGetIntegerv(GL_VIEWPORT,@viewport);

    if(Y = 0) then Y := 1;
    glReadPixels(X,round(viewport[3]-Y),1,1,GL_DEPTH_COMPONENT,GL_FLOAT,@winZ);
    gluUnProject(X,viewport[3]-Y,winZ,modelview,projection,viewport,@resPoint[0],@resPoint[1],@resPoint[2]);
    Result := resPoint;
    end;
    [/pascal]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •