feat: fix aspect ratio
This commit is contained in:
parent
85e0bf3d6c
commit
c6a4cfa418
|
@ -49,6 +49,10 @@
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "astro/twoBodyMethods.hpp"
|
#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.
|
// Initialize GLFW, OpenGL and GLEW, open a window and make it the current context.
|
||||||
// Returns 0 for success, and -1 for any failure.
|
// Returns 0 for success, and -1 for any failure.
|
||||||
// Failures are printed to STDERR.
|
// Failures are printed to STDERR.
|
||||||
|
@ -64,7 +68,7 @@ int initGraphics(GLFWwindow** window)
|
||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
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)
|
if (!window)
|
||||||
{
|
{
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
|
@ -98,8 +102,7 @@ GLint getShaderUniformLocation(GLuint shaderProgram, const std::string& uniformN
|
||||||
|
|
||||||
void updateProjectionMatrix(GLuint shaderProgram)
|
void updateProjectionMatrix(GLuint shaderProgram)
|
||||||
{
|
{
|
||||||
// Calculate matrices
|
float left = -ASPECT, right = ASPECT, bottom = -1.0, top = 1.0, near = -1.0, far = 1.0;
|
||||||
float left = -1.0, right = 1.0, bottom = -1.0, top = 1.0, near = -1.0, far = 1.0;
|
|
||||||
glm::mat4 projection = glm::ortho(left, right, bottom, top, near, far);
|
glm::mat4 projection = glm::ortho(left, right, bottom, top, near, far);
|
||||||
GLint projectionLocation = getShaderUniformLocation(shaderProgram, "_Projection");
|
GLint projectionLocation = getShaderUniformLocation(shaderProgram, "_Projection");
|
||||||
glUniformMatrix4fv(projectionLocation, 1, GL_FALSE, &projection[0][0]);
|
glUniformMatrix4fv(projectionLocation, 1, GL_FALSE, &projection[0][0]);
|
||||||
|
|
Loading…
Reference in New Issue