Lightweight OpenGL 3D Renderer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Euclid/src/window.cpp

61 lines
1.3 KiB

#include "window.hpp"
#include "GLFW/glfw3.h"
2 years ago
#include <GL/gl.h>
#include <cstdlib>
#include <stdio.h>
std::map<GLFWwindow*, Window*> Window::windowMap;
Window::Window(const char* title) {
this->_title = title;
}
Window::Window(const char* title, unsigned int w, unsigned int h) : Window(title) {
this->_width = w;
this->_height = h;
}
2 years ago
Window::~Window() {
glfwDestroyWindow(_win);
windowMap.erase(_win);
2 years ago
}
void Window::spawn() {
2 years ago
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
2 years ago
glfwWindowHint(GLFW_FLOATING, GL_TRUE);
2 years ago
_win = glfwCreateWindow(_width, _height, _title, NULL, NULL);
if (_win == NULL) {
printf("[ERROR] Failed to create a window.\n");
glfwTerminate();
exit(1);
}
// Register window in the std::map
windowMap[_win] = this;
glfwSetFramebufferSizeCallback(_win, framebufferSizeCallback);
2 years ago
glfwMakeContextCurrent(_win);
}
2 years ago
void Window::updateSize(int w, int h) {
_width = w;
_height = h;
2 years ago
glViewport(0, 0, w, h);
}
2 years ago
void Window::makeCurrent() {
glfwMakeContextCurrent(_win);
}
void Window::swapBuffers() {
glfwSwapBuffers(_win);
}
void Window::framebufferSizeCallback(GLFWwindow* win, int width, int height) {
windowMap[win]->updateSize(width, height);
}