12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include <iostream>
- #include "wrapper/Window.h"
- Window::Window(const WindowOptions& options) : window(nullptr) {
- glfwDefaultWindowHints();
- glfwWindowHint(GLFW_VISIBLE, 0);
- glfwWindowHint(GLFW_RESIZABLE, 1);
- glfwWindowHint(GLFW_DECORATED, !options.fullscreen);
- glfwWindowHint(GLFW_DOUBLEBUFFER, 1);
- if(options.es) {
- glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
- } else {
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- }
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, options.majorVersion);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, options.minorVersion);
- GLFWmonitor* monitor = options.fullscreen ? glfwGetPrimaryMonitor() : nullptr;
- window = glfwCreateWindow(options.size.width, options.size.height, options.name, monitor, nullptr);
- if(window == nullptr) {
- std::cout << "could not create window\n";
- return;
- }
- glfwMakeContextCurrent(window);
- glfwSwapInterval(options.vsync);
- }
- Window::~Window() {
- if(window != nullptr) {
- glfwDestroyWindow(window);
- }
- }
- bool Window::hasError() const {
- return window == nullptr;
- }
- void Window::show() {
- glfwShowWindow(window);
- }
- bool Window::shouldClose() const {
- return glfwWindowShouldClose(window);
- }
- void Window::swapBuffers() {
- glfwSwapBuffers(window);
- }
- void Window::trapCursor(bool trap) {
- glfwSetInputMode(window, GLFW_CURSOR, trap ? GLFW_CURSOR_DISABLED : GLFW_CURSOR_NORMAL);
- }
- Size Window::getSize() const {
- Size size(0, 0);
- glfwGetWindowSize(window, &size.width, &size.height);
- return size;
- }
- Size Window::getFramebufferSize() const {
- Size size(0, 0);
- glfwGetFramebufferSize(window, &size.width, &size.height);
- return size;
- }
- bool Window::isKeyDown(int key) const {
- return glfwGetKey(window, key) == GLFW_PRESS;
- }
|