Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Using 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 glOrtho?

share|improve this question
What "grid" are you talking about? – Nicol Bolas Jun 6 '12 at 2:34
well in glOrtho and when you get mouse callback, it is done with a non-cartesian grid where (0,0) is the top right corner. gluPerspective sets up the screen to use a cartesian grid, but it's not a 1 to 1 scale with the pixels on the screen, I need a way to make one pixel equal one unit, so that translation of one will make the character move 1 pixel. – Brendan Webster Jun 6 '12 at 3:02
What are you trying to do with a perspective projection? Are you trying to do some 2D thing with depth? – Nicol Bolas Jun 6 '12 at 3:03
it is a 3D top down shooter – Brendan Webster Jun 6 '12 at 3:08
i think you should google something about unprojecting ;) – Notabene Jun 6 '12 at 7:46
up vote 4 down vote accepted

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:

glm::mat4x4 perspective = glm::perspective(90.f, 640.f / 480.f, 0.1f, 1000.f);

// <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);
share|improve this answer
thanks for the help =D – Brendan Webster Jun 6 '12 at 14:45

Both glOrtho and gluPerspective are deprecated: OpenGL expects you to construct, manipulate, and use matrices in your own programs and shaders.

share|improve this answer
OpenGL 3.0+ also expects you to build VBO's (glBegin...glEnd and display lists are deprecated), connect a shader to everything and keep track of your own matrices, which can be a royal pain in the ass. – knight666 Jun 6 '12 at 12:31
I guess I haven't done enough research yet, all this OpenGL 3 stuff is getting to my head, I hadn't realized that you have to setup all the stuff yourself. that also explains why I couldn't figure out how to change the depth buffer – Brendan Webster Jun 6 '12 at 14:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.