diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Core/Window.cpp | 46 | ||||
| -rw-r--r-- | src/Core/Window.h | 24 | ||||
| -rw-r--r-- | src/main.c | 6 | ||||
| -rw-r--r-- | src/main.cpp | 11 |
4 files changed, 81 insertions, 6 deletions
diff --git a/src/Core/Window.cpp b/src/Core/Window.cpp new file mode 100644 index 0000000..8f1c6ea --- /dev/null +++ b/src/Core/Window.cpp @@ -0,0 +1,46 @@ +#include "Window.h" +#include <cstdint> + +namespace Donut +{ + static bool s_GLFWInitialized = false; + static uint32_t s_GLFWWindowCount = 0; + + Window::Window(const std::string& title, int width, int height) + : m_Title(title), m_Width(width), m_Height(height) + { + if (!s_GLFWInitialized) + { + glfwInit(); + s_GLFWInitialized = true; + } + + m_Window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr); + glfwMakeContextCurrent(m_Window); + + s_GLFWWindowCount++; + } + + Window::~Window() + { + glfwDestroyWindow(m_Window); + s_GLFWWindowCount--; + + if (s_GLFWWindowCount == 0) + { + glfwTerminate(); + s_GLFWInitialized = false; + } + } + + void Window::OnUpdate() const + { + glfwPollEvents(); + glfwSwapBuffers(m_Window); + } + + bool Window::ShouldClose() const + { + return glfwWindowShouldClose(m_Window); + } +}
\ No newline at end of file diff --git a/src/Core/Window.h b/src/Core/Window.h new file mode 100644 index 0000000..866d144 --- /dev/null +++ b/src/Core/Window.h @@ -0,0 +1,24 @@ +#pragma once + +#include <GLFW/glfw3.h> +#include <string> + +namespace Donut +{ + class Window + { + public: + Window(const std::string& title, int width, int height); + ~Window(); + + bool ShouldClose() const; + void OnUpdate() const; + private: + GLFWwindow* m_Window; + + std::string m_Title; + int m_Width; + int m_Height; + bool m_IsClosed; + }; +}
\ No newline at end of file diff --git a/src/main.c b/src/main.c deleted file mode 100644 index b2c1bc6..0000000 --- a/src/main.c +++ /dev/null @@ -1,6 +0,0 @@ -#include <stdio.h> - -int main(void) -{ - puts("Donut"); -}
\ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..7637a5b --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,11 @@ +#include "Core/Window.h" + +int main() +{ + Donut::Window window("Donut", 1280, 720); + + while (!window.ShouldClose()) + { + window.OnUpdate(); + } +}
\ No newline at end of file |
