Jump to content
  • Advertisement
Sign in to follow this  

Perspective Woes

This topic is 2223 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

Hi, silly issue I'm having here, it's been around for a while but it was a low priority until now. In the past, with the perspective set up as follows:
gluPerspective(45, (double)screen_width/(double)screen_height, 0.01, 1.0);

objects would not show up square -- square objects were being drawn wider than they should have been. Fiddling with gluPerspective, I came up with:
gluPerspective(90, (double)screen_width/(double)screen_height, 0.01, 1.0);

Which draws things square, but is giving me all sorts of problems with depth (Its a 2d engine, but things can be drawn on one of a couple layers of depth, plus hud type overlays) which is giving me a particular problem with my overlays, also, things get distorted again when I move objects to different layers.

How do I set up my perspective (or if perspective isn't the correct approach, an alternative) so that I can have my depth, but without size distortion (I don't want scaling or resizing with depth), so square show up square and whatnot? It needs to use the appropriate screen aspect ratio as defined by screen_width/screen_height.

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
I think glOrtho is the solution, but I'm not sure how to set it up properly. I want the center of the screen to be 0,0, top to be 1.0, bottom to be -1.0, with left and right appropriate scaled values relative to height, so that squares are square and whatnot.

Share this post


Link to post
Share on other sites
You can supply negative values into glOrtho, so if you want to go from -1 to 1, then you can call glOrtho(-1, 1, -1, 1, 0, 1); // the last two being the near/far planes.

You should also take aspect ratio into consideration, which will typically mean modifying left/right. something like:
float aspect = (float)width / (float)height
float height = 2 // going from -1 to 1!
float width = 2 * aspect
float left = width * -0.5f
float right = width * 0.5

Share this post


Link to post
Share on other sites
Ah, many thanks, that seems to have done it (though I had to set near and far as 1, 0 to get the effect I wanted... bigger number = farther away). Nice for squares to actually be squares.

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!