24 Window::~Window(
void) {
25 glfwDestroyWindow(handle);
28 GLFWwindow* Window::getHandle() {
32 int Window::getWidth() {
36 void Window::setWidth(
int width) {
39 glfwSetWindowSize(handle, width, size.y);
44 int Window::getHeight() {
48 void Window::setHeight(
int height) {
51 glfwSetWindowSize(handle, size.x, height);
56 glm::ivec2 Window::getSize() {
60 void Window::setSize(glm::ivec2 size) {
61 if (size.x > 0 && size.y > 0) {
63 glfwSetWindowSize(handle, size.x, size.y);
68 std::string Window::getTitle() {
72 void Window::setTitle(std::string title) {
74 glfwSetWindowTitle(handle, title.c_str());
77 void Window::showInfoTitle() {
78 string fps = to_string(TimeUtil::getFPS());
79 string ups = to_string(TimeUtil::getUPS());
80 string infoTitle = title +
" - FPS: " + fps +
" | UPS: " + ups;
81 glfwSetWindowTitle(handle, infoTitle.c_str());
84 void Window::centerWindow() {
85 const GLFWvidmode* vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
86 glfwSetWindowPos(handle, (vidmode->width - size.x) / 2, (vidmode->height - size.y) / 2);
90 KeyCallback::setCurrent(callback);
91 glfwSetKeyCallback(handle, KeyCallback::dispatch);
95 MouseButtonCallback::setCurrent(callback);
96 glfwSetMouseButtonCallback(handle, MouseButtonCallback::dispatch);
99 void Window::update() {
104 bool Window::shouldClose() {
105 return glfwWindowShouldClose(handle) == GLFW_TRUE;
108 void Window::sync(
int fps) {
112 double now = TimeUtil::getTime();
113 double lastLoopTime = TimeUtil::getLastLoopTime();
114 double targetTime = 1.0 / double(fps);
117 while (now - lastLoopTime < targetTime) {
118 this_thread::yield();
119 this_thread::sleep_for(chrono::nanoseconds(1000));
121 now = TimeUtil::getTime();
126 glm::dvec2 Window::getCursorPos() {
128 glfwGetCursorPos(handle, &position.x, &position.y);
132 double Window::getCursorX() {
133 return getCursorPos().x;
136 double Window::getCursorY() {
137 return getCursorPos().y;
Generic namespace for the SimpleGL framework.
This class wraps a GLFW key callback.