7static bool isGLFWInitialized =
false;
9static void GLFWErrorCallback(
int error,
const char *description)
11 fprintf(stderr,
"GLFW Error: %d: %s\n", error, description);
16 if (isGLFWInitialized)
23 std::cout <<
"Error in initializeing GLFW!" << std::endl;
27 glfwSetErrorCallback(GLFWErrorCallback);
28 glfwWindowHint(GLFW_MAXIMIZED, GL_TRUE);
29 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
30 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
31 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
32 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
33 isGLFWInitialized =
true;
37Window::Window(std::string title =
"Window")
40 m_Window = glfwCreateWindow(640, 480, title.c_str(), NULL, NULL);
45 std::cout <<
"Error in creating window!" << std::endl;
50 glfwMakeContextCurrent(m_Window);
53void Window::SetVSync(
bool enabled)
55 if (enabled == vSyncState)
75 glClearColor(m_ClearColor.r, m_ClearColor.g, m_ClearColor.b, 1.0);
76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
79void Window::SetFullScreen(
bool fullscreen)
81 if (isFullscreen == fullscreen)
88 isFullscreen = fullscreen;
93 glfwGetWindowPos(m_Window, &x, &y);
94 glfwGetWindowSize(m_Window, &sx, &sy);
96 const GLFWvidmode *mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
98 glfwSetWindowMonitor(m_Window, glfwGetPrimaryMonitor(), 0, 0, mode->width, mode->height, 0);
104 glfwSetWindowMonitor(m_Window,
nullptr, x, y, sx, sy, 0);
108void Window::SetVisible(
bool visibility)
112 glfwShowWindow(m_Window);
117 glfwHideWindow(m_Window);
128 if (glfwWindowShouldClose(m_Window))
130 if(m_CloseEventCallback)
132 m_CloseEventCallback(0, 0);
138 glfwSwapBuffers(m_Window);
142void Window::SetMouseCallback(EventFn callback)
144 m_MouseEventCallback = callback;
147void Window::SetResizeCallback(EventFn callback)
149 m_ResizeEventCallback = callback;
152void Window::SetShouldCloseCallback(EventFn callback)
154 m_CloseEventCallback = callback;
159 m_ClearColor = color;
162void Window::MakeCurrentContext()
166 glfwMakeContextCurrent(m_Window);
173 std::cout <<
"Destroying Window!" << std::endl;
180 glfwDestroyWindow(m_Window);