Fixed aspect ratio bug

main
Elias Almqvist 2 years ago
parent 1cd7922454
commit d1581fc52e
  1. 8
      headers/renderer.hpp
  2. 4
      src/main.cpp
  3. 9
      src/renderer.cpp
  4. 3
      src/window.cpp

@ -49,20 +49,22 @@ namespace Renderer {
class Camera : public Object {
public:
glm::mat4 projection = glm::mat4(1.0f);
glm::mat4 view = glm::mat4(1.0f);
float FOV;
Camera(Window* win);
Camera(Window* win, glm::vec3 pos);
Camera(Window* win, glm::vec3 pos, glm::vec3 angle);
void setFOV(float deg);
glm::mat4 getProjection();
protected:
Window* window;
glm::vec3 front = glm::vec3(0.0f, 0.0f, 1.0f);
glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
void updateCameraTransforms();
private:
glm::mat4 projection = glm::mat4(1.0f);
};
@ -90,7 +92,7 @@ namespace Renderer {
void setCamera(Camera *cam);
void spawnObject(RenderObject *ro);
void render();
protected:
// protected:
Camera *camera;
private:
std::vector<RenderObject*> renderObjects = std::vector<RenderObject*>();

@ -105,6 +105,7 @@ std::vector<unsigned int> indices({
// Window for the game
Window win("Euclid Engine: Demo");
Renderer::Scene scene(&win);
void framebuffer_size_callback(GLFWwindow* glfwWindow, int w, int h) {
win.updateSize(w, h);
@ -138,12 +139,11 @@ int main() {
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
// Create scene
Renderer::Scene scene(&win);
Renderer::TexturedObject ro(verts, indices);
Renderer::TexturedObject ro2(verts, indices);
ro.setTexture(RUSTY_METAL_TEXTURE);
ro2.setTexture("assets/textures/meep.jpg"); // TODO: fix texture bug
ro.setTexture(RUSTY_METAL_TEXTURE);
scene.spawnObject(&ro);
scene.spawnObject(&ro2);

@ -105,7 +105,7 @@ namespace Renderer {
// Camera
Camera::Camera(Window* win) {
window = win;
setFOV(DEFAULT_FOV);
FOV = DEFAULT_FOV;
}
Camera::Camera(Window* win, glm::vec3 pos) : Camera(win) {
@ -116,8 +116,9 @@ namespace Renderer {
setRotation(angle);
}
void Camera::setFOV(float fov) {
projection = glm::perspective(glm::radians(fov), (float)window->width() / (float)window->height(), NEAR_PLANE, FAR_PLANE);
glm::mat4 Camera::getProjection() {
projection = glm::perspective(glm::radians(FOV), (float)window->width() / (float)window->height(), NEAR_PLANE, FAR_PLANE);
return projection;
}
void Camera::updateCameraTransforms() {
@ -173,7 +174,7 @@ namespace Renderer {
shader.setMat4("model", modelTransform);
shader.setMat4("view", cam.view);
shader.setMat4("projection", cam.projection);
shader.setMat4("projection", cam.getProjection());
shader.use();

@ -31,10 +31,7 @@ void Window::spawn() {
}
void Window::updateSize(int w, int h) {
// int w, h;
// glfwGetWindowSize(win, &w, &h);
_width = w;
_height = h;
glViewport(0, 0, w, h);
printf("New size: %i %i\n", w, h);
}

Loading…
Cancel
Save