Jump to content
  • Advertisement
Sign in to follow this  
gorgorath

keeping viewport aspect ratio

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

right now i have a viewport created that fills the entire gl canvas glviewport(0,0, width, height) but i want to create a viewport from a image's width and height. So that the aspect ratio of the viewport is the same as that of the image. It is i believe pretty simple, to achieve this..but the code is driving me crazy:) any help would be appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Aspect ratio is defined as the width divided by the height (aspect = width / height). For example, a 640x480 display would have an aspect ratio of ~1.333.

If you want to use a different width while keeping the aspect, just solve for height by dividing the width by the desired aspect ratio.

Share this post


Link to post
Share on other sites
To mostly cover the available area, check for the constraining dimension like so

if( available_width/image_width <= available_height/image_height ) {
// use full available width, compute height from aspect ratio as bpoint said
} else {
// use full available height, compute width from aspect ratio similarly as bpoint said
}

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!