Jump to content
  • Advertisement
Sign in to follow this  
kcirrem

OpenGL From Ortho to Perspective

This topic is 4113 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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. ;)

Share this post


Link to post
Share on other sites
Quote:
Original post by jouley
Nor, as our references say, should the near clipping plane be 0. ;)
Heh, my bad!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!