blob: 3a6ba2c31b53b912375f4c3c085b8188dc1f18d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#include "window.h"
#include <cstdint>
namespace Donut
{
static bool s_glfw_initialized = false;
static uint32_t s_glfw_window_count = 0;
Window::Window(const std::string& title, int width, int height)
: m_title(title), m_width(width), m_height(height)
{
if (!s_glfw_initialized)
{
glfwInit();
s_glfw_initialized = true;
}
m_window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
glfwMakeContextCurrent(m_window);
s_glfw_window_count++;
}
Window::~Window()
{
glfwDestroyWindow(m_window);
s_glfw_window_count--;
if (s_glfw_window_count == 0)
{
glfwTerminate();
s_glfw_initialized = false;
}
}
void Window::on_update() const
{
glfwPollEvents();
glfwSwapBuffers(m_window);
}
bool Window::should_close() const
{
return glfwWindowShouldClose(m_window);
}
}
|