title: Translating mouse coordinates to world space coordinates
body: <p>I'm using GLFW and I want to get world space coordinates by mouse coordinates on window to drawing objects while clicking in selected place. Firstly I was trying to get this coordinates using only matrices transformations but as a result i did not get anything with sense.</p>
  
  <pre><code>glfwGetCursorPos(window, &amp;xPos, &amp;yPos);
  mat4 inverse_projection = glm::inverse(projection);
  mat4 inverse_view = glm::inverse(view);
  
  GLdouble normalized_coord2D_x = (2.0 * xPos / -1.0),
      normalized_coord2D_y = (2.0 * yPos / -1.0);
  
  vec4 worldCoordNear;
  vec4 worldCoordFar;
  
  vec4 normalizedCoordNear = vec4(normalized_coord2D_x, normalized_coord2D_y, -1.0, 1.0);
  vec4 clipCoordNear = normalizedCoordNear;
  vec4 eyeCoordNear = inverse_projection * clipCoordNear;
  worldCoordNear /= worldCoordNear.w;
  
  vec4 normalizedCoordFar = vec4(normalized_coord2D_x, normalized_coord2D_y, 1.0, 1.0);
  vec4 clipCoordFar = normalizedCoordFar;
  vec4 eyeCoordFar = inverse_projection * clipCoordFar;
  worldCoordFar = inverse_view * eyeCoordFar;
  worldCoordFar /= worldCoordFar.w;
  </code></pre>
  
  <p>Now I gave up from that solution and trying to solve the problem with gluUnProject on simple 2D scene, my function looks like:</p>
  
  <pre><code>void mouseButtonCallback(GLFWwindow *window, int button, int action, int mods)
  {
      if (button == GLFW_MOUSE_BUTTON_LEFT &amp;&amp; action == GLFW_PRESS) {
      std::cout &lt;&lt; "Left button pressed" &lt;&lt; std::endl;
  
      GLdouble xPos, yPos;
      glfwGetCursorPos(window, &amp;xPos, &amp;yPos);
  
      GLint viewport[4];
      GLdouble modelview[16];
      GLdouble projection[16];
      GLfloat winX, winY, winZ;
      GLdouble posX, posY, posZ;
  
      glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
      glGetDoublev(GL_PROJECTION_MATRIX, projection);
      glGetIntegerv(GL_VIEWPORT, viewport);
  
      winX = (float)xPos;
      winY = (float)viewport[3] - (float)yPos;
      glReadPixels(xPos, int(winY), 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &amp;winZ);
  
      gluUnProject(winX, winY, winZ, modelview, projection, viewport, &amp;posX, &amp;posY, &amp;posZ);
      }
  }
  </code></pre>
  
  <p>And I am getting error:</p>
  
  <blockquote>
    <p>LNK2019 unresolved external symbol _gluUnProject@48 referenced in
    function "void __cdecl mouseButtonCallback(struct
    GLFWwindow*,int,int,int)"
    (?mouseButtonCallback@@YAXPAUGLFWwindow@@HHH@Z)</p>
  </blockquote>
  
  <p>I am working on VS2015 and that's my includes:</p>
  
  <pre><code>#include &lt;GL/glew.h&gt;
  #include &lt;GLFW/glfw3.h&gt;
  #include &lt;math.h&gt;
  #include &lt;iostream&gt;
  #include &lt;GL/GLU.h&gt;
  #include &lt;Windows.h&gt;
  </code></pre>
  
  <p>It is worth pointing out that the glu library I downloaded with NuGet Packages</p>
  
  <p>I would be very grateful for all the help and an explanation on how to solve the problem.</p>