From Ortho to Perspective

Started by
4 comments, last by kcirrem 17 years ago
I'm writing a tile-based mini-rpg in OpenGL. At the moment I am setting up my screen like so:

	glMatrixMode(GL_PROJECTION);

	glLoadIdentity();
	glOrtho(0.0f, 640.0f, 480.0f, 0.0f, -1000.0f, 1000.0f);
	glMatrixMode(GL_MODELVIEW);

	glLoadIdentity();
This works great, I've got the map loaded and rendering, 3D objects rendering where they're supposed to, pathfinding, etc. all going. However, I would like to try out how it looks in a perspective view (similar angle to Warcraft 3). I thought replacing the glOrtho line with the following would work:

	glFrustum(0.0f, 640.0f, 480.0f, 0.0f, -1000.0f, 1000.0f);
but instead nothing shows at all, no map, no objects, nothing. Shouldn't it be comparable with what I originally set up?
Advertisement
From the docs:
Quote:Errors:
GL_INVALID_VALUE is generated if nearVal or farVal is not positive, or if Left = Right, or bottom = top.

To me, for a 2D game, that range seems pretty high to begin with, and you may need to do some tweaking for things to work exactly right in perspective view, mostly with those near and far clipping planes and the depths of whatever you render.

Golly, that was a long sentence.

Best of luck!
-jouley
the left/right/top/bottom parameters for glFrustum are not in screen space (i.e. they should not be 0,0/640,480).

See this example I copied from flipcode
void setFov(GLfloat fov) {    GLfloat w = winW / winH;//width and height of the window    glMatrixMode(GL_PROJECTION);    glFrustum (-w, w, -1.0, 1.0, 0.0f, 1000.0f);    glMatrixMode(GL_MODELVIEW);    glViewport(0, 0, winW, winH);} 


Also, the the near and far clipping planes must be positive
Quote:Original post by Hodgman
the left/right/top/bottom parameters for glFrustum are not in screen space (i.e. they should not be 0,0/640,480).

Also good to note!

Quote:See this example I copied from flipcode
*** Source Snippet Removed ***

Also, the the near and far clipping planes must be positive

Nor, as our references say, should the near clipping plane be 0. ;)
Quote:Original post by jouley
Nor, as our references say, should the near clipping plane be 0. ;)
Heh, my bad!
Thanks for the help guys :)

Didn't take much more to get it working, just a couple of constants needed to be changed (thank God I don't hard code widths & heights anywhere).

Had to reverse the drawing order of some things though, and the camera took a bit of a beating which was something I didn't expect, but overall working well.

Thanks again.

This topic is closed to new replies.

Advertisement