Fixed wrapper class for windows

pull/6/head
E. Almqvist 2 years ago
parent 477f72e139
commit 5e88f63273
  1. 2
      headers/window.hpp
  2. 14
      src/main.cpp
  3. 11
      src/window.cpp

@ -35,4 +35,6 @@ class Window {
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; }
static void framebufferSizeCallback(GLFWwindow* win, int width, int height);
}; };

@ -104,13 +104,6 @@ std::vector<unsigned int> indices({
// Window for the game // 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);
}
void processInput(GLFWwindow *win) { void processInput(GLFWwindow *win) {
int action = glfwGetKey(win, GLFW_KEY_ESCAPE); int action = glfwGetKey(win, GLFW_KEY_ESCAPE);
if (action == GLFW_PRESS) { if (action == GLFW_PRESS) {
@ -120,6 +113,9 @@ void processInput(GLFWwindow *win) {
int main() { int main() {
// Spawn window // Spawn window
Window win("Euclid Engine: Demo");
Renderer::Scene scene(&win);
win.spawn(); win.spawn();
if ( !gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) ) { if ( !gladLoadGLLoader((GLADloadproc)glfwGetProcAddress) ) {
@ -127,8 +123,8 @@ int main() {
return 1; return 1;
} }
glViewport(0, 0, win.getWidth(), win.getHeight()); // glViewport(0, 0, win.getWidth(), win.getHeight());
glfwSetFramebufferSizeCallback(win.getWindow(), framebuffer_size_callback); // Framebuffer // glfwSetFramebufferSizeCallback(win.getWindow(), framebuffer_size_callback); // Framebuffer
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);

@ -4,6 +4,8 @@
#include <cstdlib> #include <cstdlib>
#include <stdio.h> #include <stdio.h>
std::map<GLFWwindow*, Window*> Window::windowMap;
Window::Window(const char* title) { Window::Window(const char* title) {
this->_title = title; this->_title = title;
} }
@ -15,6 +17,7 @@ Window::Window(const char* title, unsigned int w, unsigned int h) : Window(title
Window::~Window() { Window::~Window() {
glfwDestroyWindow(_win); glfwDestroyWindow(_win);
windowMap.erase(_win);
} }
void Window::spawn() { void Window::spawn() {
@ -31,6 +34,10 @@ void Window::spawn() {
exit(1); exit(1);
} }
// Register window in the std::map
windowMap[_win] = this;
glfwSetFramebufferSizeCallback(_win, framebufferSizeCallback);
glfwMakeContextCurrent(_win); glfwMakeContextCurrent(_win);
} }
@ -47,3 +54,7 @@ void Window::makeCurrent() {
void Window::swapBuffers() { void Window::swapBuffers() {
glfwSwapBuffers(_win); glfwSwapBuffers(_win);
} }
void Window::framebufferSizeCallback(GLFWwindow* win, int width, int height) {
windowMap[win]->updateSize(width, height);
}

Loading…
Cancel
Save