feat: fix aspect ratio

This commit is contained in:
Cat Flynn 2023-08-03 10:27:07 +02:00 committed by ktyl
parent 85e0bf3d6c
commit c6a4cfa418
1 changed files with 6 additions and 3 deletions

View File

@ -49,6 +49,10 @@
#include <cmath>
#include "astro/twoBodyMethods.hpp"
const int WIDTH = 640;
const int HEIGHT = 480;
const float ASPECT = (float)WIDTH / (float)HEIGHT;
// Initialize GLFW, OpenGL and GLEW, open a window and make it the current context.
// Returns 0 for success, and -1 for any failure.
// Failures are printed to STDERR.
@ -64,7 +68,7 @@ int initGraphics(GLFWwindow** window)
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
*window = glfwCreateWindow(640, 480, "Hello Astro", NULL, NULL);
*window = glfwCreateWindow(WIDTH, HEIGHT, "Hello Astro", NULL, NULL);
if (!window)
{
glfwTerminate();
@ -98,8 +102,7 @@ GLint getShaderUniformLocation(GLuint shaderProgram, const std::string& uniformN
void updateProjectionMatrix(GLuint shaderProgram)
{
// Calculate matrices
float left = -1.0, right = 1.0, bottom = -1.0, top = 1.0, near = -1.0, far = 1.0;
float left = -ASPECT, right = ASPECT, bottom = -1.0, top = 1.0, near = -1.0, far = 1.0;
glm::mat4 projection = glm::ortho(left, right, bottom, top, near, far);
GLint projectionLocation = getShaderUniformLocation(shaderProgram, "_Projection");
glUniformMatrix4fv(projectionLocation, 1, GL_FALSE, &projection[0][0]);