openglviewportprojectiongluopenglcontext

Where can I call gluUnproject?


This is a really simple question.

Where can I call gluUnproject? Do I need a current openGL context of some kind?

I looked up the function here, but that isn't telling me if there's any kind of precondition.

I want to do this:

    GLdouble near[3];

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    eq::Matrix4f projection;
    getView()->getProjection(projection);
    GLdouble *projMatrix = Matrix4d(projection).array;
    glMultMatrixd(projMatrix);

    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity();
    eq::Matrix4f camera;
    getView()->getCamera(camera);
    GLdouble *modelMatrix = Matrix4d(camera).array;
    glMultMatrixd(modelMatrix);

    const PixelViewport pvp = event.context.pvp;
    int viewport[4] = {pvp.x, pvp.y, pvp.w, pvp.h};

    // SCREEN HEIGHT NOT CONTEXT HEIGHT
    const int y = (int)getWindow()->getPixelViewport().h - event.pointerButtonPress.y;

    gluUnProject(
                             event.pointerButtonPress.x,
                             y,
                             0.0,
                             modelMatrix,
                             projMatrix,
                             viewport,
                             &near[0], 
                             &near[1], 
                             &near[2] 
                             );

    near[2] = 1.0f;
    GLdouble far[3] = {near[0],near[1], -1.0f};

On my server node instead of having to pass it to my render nodes, and have them return the result. The server doesn't have an openGL context. Can I still call gluUnproject?


Solution

  • gluUnProject is not part of OpenGL. It's part of GLU. Technically you can use all of the GLU functions which don't access OpenGL without having a context at all. gluUnProject is such a function.