parent
259c25a621
commit
1de6a7280b
@ -1,13 +1,29 @@ |
|||||||
#pragma once |
#pragma once |
||||||
#define WINDOW_WIDTH 640 |
#include "GLFW/glfw3.h" |
||||||
#define WINDOW_HEIGHT 480 |
|
||||||
|
|
||||||
|
// Default window dimensions
|
||||||
|
#define D_WINDOW_TITLE "Euclid Engine" |
||||||
|
#define D_WINDOW_WIDTH 640 |
||||||
|
#define D_WINDOW_HEIGHT 480 |
||||||
|
|
||||||
class Window { |
class Window { |
||||||
public: |
public: |
||||||
Window(); |
GLFWwindow* win; |
||||||
|
|
||||||
protected: |
Window(const char* title); |
||||||
const char* title = "Euclid Engine"; |
Window(const char* title, unsigned int w, unsigned int h); |
||||||
|
|
||||||
|
void spawn(); |
||||||
|
|
||||||
|
unsigned int width() { return _width; } // getters and dumb and
|
||||||
|
unsigned int height() { return _height; } // cpp should have readonly fields...
|
||||||
|
|
||||||
|
private: |
||||||
|
const char* _title = D_WINDOW_TITLE; |
||||||
|
unsigned int _width = D_WINDOW_WIDTH; |
||||||
|
unsigned int _height = D_WINDOW_HEIGHT; |
||||||
|
|
||||||
|
void updateSize();
|
||||||
|
void setWidth(unsigned int w) { _width = w; } |
||||||
|
void setHeight(unsigned int h) { _height = h; } |
||||||
}; |
}; |
||||||
|
@ -0,0 +1,36 @@ |
|||||||
|
#include "window.hpp" |
||||||
|
#include "GLFW/glfw3.h" |
||||||
|
#include <cstdlib> |
||||||
|
#include <stdio.h> |
||||||
|
|
||||||
|
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; |
||||||
|
} |
||||||
|
|
||||||
|
void Window::spawn() { |
||||||
|
glfwInit();
|
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); |
||||||
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
||||||
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |
||||||
|
|
||||||
|
win = glfwCreateWindow(_width, _height, _title, NULL, NULL); |
||||||
|
if (win == NULL) { |
||||||
|
printf("[ERROR] Failed to create a window.\n"); |
||||||
|
glfwTerminate(); |
||||||
|
exit(1); |
||||||
|
} |
||||||
|
|
||||||
|
glfwMakeContextCurrent(win); |
||||||
|
} |
||||||
|
|
||||||
|
void Window::updateSize() { |
||||||
|
int w, h; |
||||||
|
glfwGetWindowSize(win, &w, &h); |
||||||
|
_width = w; |
||||||
|
_height = h; |
||||||
|
} |
Loading…
Reference in new issue