Luís Jesus
Luís Jesus

Reputation: 1678

Converting Orthogonal Camera to Perspective OpenGL

I'm having some troubles converting a orthogonal camera to a perspective one, using OpenGL. I currently have my orthogonal camera following a middle point of two objects, using:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,_winWidth,0,_winHeight,150,-150);
glTranslated(-_middlePoint[0]+_winWidth/2, -_middlePoint[1]+_winHeight/2, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

The above code works perfectly, now i'm trying to use it like this:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, _winWidth/_winHeight, 1.0, 1000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0, 0, 800, _middlePoint[0], _middlePoint[1], 50, 0, 0, 1);
glLoadIdentity();

And I simply get a black screen. Any thoughts? I've tried changing the up vector from 0,0,1 to 0,1,0 and it stays the same.

Any help appreciated.

Upvotes: 0

Views: 2057

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490148

If you have code working using glOrtho already, you can normally switch to a perspective projection by simply changing that to glFrustum. If you're writing new code, gluPerspective and gluLookat may be easier, but for code that already works using an orthographic projection, it's easy to switch to perspective by just calling glFrustum with the same parameters.

Upvotes: 1

Related Questions