Window.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <iostream>
  2. #include "client/rendering/wrapper/Window.h"
  3. Window::Window(const Size& size, const char* windowName) : window(nullptr) {
  4. glfwDefaultWindowHints();
  5. glfwWindowHint(GLFW_VISIBLE, 0);
  6. glfwWindowHint(GLFW_RESIZABLE, 1);
  7. glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
  8. glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
  9. glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  10. window = glfwCreateWindow(size.width, size.height, windowName, nullptr, nullptr);
  11. if(window == nullptr) {
  12. std::cout << "could not create window\n";
  13. return;
  14. }
  15. glfwMakeContextCurrent(window);
  16. glfwSwapInterval(1);
  17. glfwSetWindowUserPointer(window, this);
  18. }
  19. Window::~Window() {
  20. if(window != nullptr) {
  21. glfwDestroyWindow(window);
  22. }
  23. }
  24. bool Window::hasError() const {
  25. return window == nullptr;
  26. }
  27. void Window::show() {
  28. glfwShowWindow(window);
  29. }
  30. bool Window::shouldClose() const {
  31. return glfwWindowShouldClose(window);
  32. }
  33. void Window::swapBuffers() {
  34. glfwSwapBuffers(window);
  35. }
  36. void Window::setFramebufferSizeCallback(GLFWframebuffersizefun f) {
  37. glfwSetFramebufferSizeCallback(window, f);
  38. }
  39. void Window::setKeyCallback(GLFWkeyfun f) {
  40. glfwSetKeyCallback(window, f);
  41. }
  42. void Window::setMouseButtonCallback(GLFWmousebuttonfun f) {
  43. glfwSetMouseButtonCallback(window, f);
  44. }
  45. void Window::setCursorPosCallback(GLFWcursorposfun f) {
  46. glfwSetCursorPosCallback(window, f);
  47. }