| 13 | namespace ZEngine::Window::GLFWWindow { |
| 14 | |
| 15 | OpenGLWindow::OpenGLWindow(WindowProperty& prop) |
| 16 | : CoreWindow() |
| 17 | |
| 18 | { |
| 19 | m_property = prop; |
| 20 | int glfw_init = glfwInit(); |
| 21 | |
| 22 | if (glfw_init == GLFW_FALSE) { |
| 23 | ZENGINE_CORE_CRITICAL("Unable to initialize glfw.."); |
| 24 | ZENGINE_EXIT_FAILURE(); |
| 25 | } |
| 26 | |
| 27 | glfwWindowHint(GLFW_DEPTH_BITS, 32); |
| 28 | glfwWindowHint(GLFW_STENCIL_BITS, 8); |
| 29 | glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE); |
| 30 | |
| 31 | #ifdef __APPLE__ |
| 32 | m_desired_gl_context_major_version = 4; |
| 33 | m_desired_gl_context_minor_version = 1; |
| 34 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); |
| 35 | #endif |
| 36 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |
| 37 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, m_desired_gl_context_major_version); |
| 38 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, m_desired_gl_context_minor_version); |
| 39 | |
| 40 | glfwSetErrorCallback([](int error, const char* description) { |
| 41 | ZENGINE_CORE_CRITICAL(description); |
| 42 | ZENGINE_EXIT_FAILURE(); |
| 43 | }); |
| 44 | |
| 45 | m_native_window = glfwCreateWindow(m_property.Width, m_property.Height, m_property.Title.c_str(), NULL, NULL); |
| 46 | |
| 47 | ZENGINE_CORE_INFO("Window created, Properties : Width = {0}, Height = {1}", m_property.Width, m_property.Height); |
| 48 | |
| 49 | glfwSetWindowUserPointer(m_native_window, &m_property); |
| 50 | |
| 51 | glfwSetFramebufferSizeCallback(m_native_window, OpenGLWindow::__OnGlfwFrameBufferSizeChanged); |
| 52 | |
| 53 | glfwSetWindowCloseCallback(m_native_window, OpenGLWindow::__OnGlfwWindowClose); |
| 54 | glfwSetWindowSizeCallback(m_native_window, OpenGLWindow::__OnGlfwWindowResized); |
| 55 | glfwSetWindowMaximizeCallback(m_native_window, OpenGLWindow::__OnGlfwWindowMaximized); |
| 56 | glfwSetWindowIconifyCallback(m_native_window, OpenGLWindow::__OnGlfwWindowMinimized); |
| 57 | |
| 58 | glfwSetMouseButtonCallback(m_native_window, OpenGLWindow::__OnGlfwMouseButtonRaised); |
| 59 | glfwSetScrollCallback(m_native_window, OpenGLWindow::__OnGlfwMouseScrollRaised); |
| 60 | glfwSetKeyCallback(m_native_window, OpenGLWindow::__OnGlfwKeyboardRaised); |
| 61 | |
| 62 | glfwSetCursorPosCallback(m_native_window, OpenGLWindow::__OnGlfwCursorMoved); |
| 63 | glfwSetCharCallback(m_native_window, OpenGLWindow::__OnGlfwTextInputRaised); |
| 64 | } |
| 65 | |
| 66 | bool OpenGLWindow::HasContext() const { |
| 67 | return m_context != nullptr; |
nothing calls this directly
no outgoing calls
no test coverage detected