NoJobEngine 2.0.7
Loading...
Searching...
No Matches
Window.cpp
Go to the documentation of this file.
3#include <GLFW/glfw3.h>
4#include <stdexcept>
5
6namespace NoJob {
7namespace { std::uint32_t s_WindowCount = 0; }
8
10 if (s_WindowCount == 0 && glfwInit() != GLFW_TRUE)
11 throw std::runtime_error("NoJobEngine: GLFW initialization failed.");
12
13 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
14 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
15 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
16
17 m_Window = glfwCreateWindow(
18 static_cast<int>(props.Width),
19 static_cast<int>(props.Height),
20 props.Title.c_str(), nullptr, nullptr);
21
22 if (!m_Window) {
23 if (s_WindowCount == 0) glfwTerminate();
24 throw std::runtime_error("NoJobEngine: window creation failed.");
25 }
26
27 ++s_WindowCount;
28 OpenGLContext::Init(m_Window);
29 glfwSwapInterval(1);
30}
31
33 if (!m_Window) return;
34 glfwDestroyWindow(m_Window);
35 m_Window = nullptr;
36 if (--s_WindowCount == 0) glfwTerminate();
37}
38
39bool Window::ShouldClose() const {
40 return glfwWindowShouldClose(m_Window) == GLFW_TRUE;
41}
42void Window::PollEvents() const { glfwPollEvents(); }
43void Window::SwapBuffers() const { glfwSwapBuffers(m_Window); }
44}
OpenGLContext declarations for the OpenGL Backend subsystem.
Window declarations for the Core subsystem.
static void Init(GLFWwindow *window)
void SwapBuffers() const
Definition Window.cpp:43
void PollEvents() const
Definition Window.cpp:42
Window(const WindowProps &props)
Definition Window.cpp:9
bool ShouldClose() const
Definition Window.cpp:39
std::uint32_t Height
Definition Window.h:15
std::string Title
Definition Window.h:13
std::uint32_t Width
Definition Window.h:14