Elias Almqvist 2 years ago
parent 99e57ec654
commit f6354c5a7d
  1. 11
      headers/window.hpp
  2. 6
      src/controller.cpp
  3. 10
      src/main.cpp
  4. 9
      src/window.cpp

@ -1,17 +1,18 @@
#pragma once #pragma once
// #include "renderer.hpp"
#include <glad/glad.h>
#include "GLFW/glfw3.h" #include "GLFW/glfw3.h"
// Default window dimensions // Default window dimensions
#define D_WINDOW_TITLE "Euclid Engine" #define D_WINDOW_TITLE "Euclid Engine"
// #define D_WINDOW_WIDTH 640 #define D_WINDOW_WIDTH 640
// #define D_WINDOW_HEIGHT 480 #define D_WINDOW_HEIGHT 480
#define D_WINDOW_WIDTH 1920
#define D_WINDOW_HEIGHT 1080
class Window { class Window {
public: public:
GLFWwindow* win; GLFWwindow* win;
// Renderer::Camera cam;
Window(const char* title); Window(const char* title);
Window(const char* title, unsigned int w, unsigned int h); Window(const char* title, unsigned int w, unsigned int h);
@ -21,12 +22,12 @@ class Window {
unsigned int width() { return _width; } // getters and dumb and unsigned int width() { return _width; } // getters and dumb and
unsigned int height() { return _height; } // cpp should have readonly fields... unsigned int height() { return _height; } // cpp should have readonly fields...
void updateSize(int w, int h);
private: private:
const char* _title = D_WINDOW_TITLE; const char* _title = D_WINDOW_TITLE;
unsigned int _width = D_WINDOW_WIDTH; unsigned int _width = D_WINDOW_WIDTH;
unsigned int _height = D_WINDOW_HEIGHT; unsigned int _height = D_WINDOW_HEIGHT;
void updateSize();
void setWidth(unsigned int w) { _width = w; } void setWidth(unsigned int w) { _width = w; }
void setHeight(unsigned int h) { _height = h; } void setHeight(unsigned int h) { _height = h; }
}; };

@ -6,6 +6,8 @@
#include <cmath> #include <cmath>
#include <cstdio> #include <cstdio>
// TODO: move file into examples
void Controller::processMouseInput(float deltaTime) { void Controller::processMouseInput(float deltaTime) {
double x, y; double x, y;
glfwGetCursorPos(window->win, &x, &y); glfwGetCursorPos(window->win, &x, &y);
@ -41,8 +43,8 @@ void Controller::processMouseInput(float deltaTime) {
updateCameraTransforms(); updateCameraTransforms();
printf("%f %f %f (pitch: %f yaw: %f)\n", position.x, position.y, position.z, pitch, yaw); // printf("%f %f %f (pitch: %f yaw: %f)\n", position.x, position.y, position.z, pitch, yaw);
} }
void Controller::processInput(float deltaTime) { void Controller::processInput(float deltaTime) {
processMouseInput(deltaTime); processMouseInput(deltaTime);

@ -102,8 +102,12 @@ std::vector<unsigned int> indices({
11, 12, 13, 11, 12, 13,
}); });
void framebuffer_size_callback(GLFWwindow* win, int w, int h) {
glViewport(0, 0, w, h); // Window for the game
Window win("Euclid Engine: Demo");
void framebuffer_size_callback(GLFWwindow* glfwWindow, int w, int h) {
win.updateSize(w, h);
} }
void processInput(GLFWwindow *win) { void processInput(GLFWwindow *win) {
@ -114,7 +118,7 @@ void processInput(GLFWwindow *win) {
} }
int main() { int main() {
Window win("Euclid Engine: Demo"); // Spawn window
win.spawn(); win.spawn();
if ( !gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) ) { if ( !gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) ) {

@ -1,5 +1,6 @@
#include "window.hpp" #include "window.hpp"
#include "GLFW/glfw3.h" #include "GLFW/glfw3.h"
#include <GL/gl.h>
#include <cstdlib> #include <cstdlib>
#include <stdio.h> #include <stdio.h>
@ -29,9 +30,11 @@ void Window::spawn() {
glfwMakeContextCurrent(win); glfwMakeContextCurrent(win);
} }
void Window::updateSize() { void Window::updateSize(int w, int h) {
int w, h; // int w, h;
glfwGetWindowSize(win, &w, &h); // glfwGetWindowSize(win, &w, &h);
_width = w; _width = w;
_height = h; _height = h;
glViewport(0, 0, w, h);
printf("New size: %i %i\n", w, h);
} }

Loading…
Cancel
Save