Created
August 16, 2014 03:03
-
-
Save christophercrouzet/1fea72d0d88e5a0dca16 to your computer and use it in GitHub Desktop.
OpenGL projection matrix to fit the content to the window while preserving the aspect ratio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int shorterSide = std::min(width, height); | |
GLfloat marginX = 1.0f + GLfloat(width - shorterSide) / (GLfloat)shorterSide; | |
GLfloat marginY = 1.0f + GLfloat(height - shorterSide) / (GLfloat)shorterSide; | |
glm::mat4 projection = glm::ortho(-marginX, marginX, -marginY, marginY); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment