gluPerspective makes OpenGL's grid really messy and rather hard to use especially when trying to do mouse input. The grid that perspective uses is completely messed up compared to the grid you get with the mouse. When using
glOrtho the grid is fixed to the mouse grid, but then you can only do 2D work, how would I set up perspective to get the same results as if I were using
If you want to use a perspective matrix for rendering, but an orthographic projection for retrieving mouse input, why not set up both?
// this example uses the free and open source OpenGL Mathematics library // you can get it here: http://glm.g-truc.net/ glm::mat4x4 perspective = glm::perspective(90.f, 640.f / 480.f, 0.1f, 1000.f); glMatrixMode(GL_PROJECTION); glLoadMatrixf(glm::value_ptr(perspective)); // <render game here> // get mouse in world coordinates glm::vec3 mouse = GetMousePosition3D(); glm::mat4x4 camera = GetCameraMatrix(); glm::mat4x4 orthographic = glm::ortho(0.f, 640.f, 480.f, 0.f); glm::vec4 viewport(0.f, 640.f, 0.f, 480.f); glm::vec3 mouse_world = glm::unProject(mouse, camera, orthographic, viewport);