diff options
| -rw-r--r-- | premake5.lua | 37 | ||||
| -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 |
5 files changed, 113 insertions, 11 deletions
diff --git a/premake5.lua b/premake5.lua index 4762b1c..91d440a 100644 --- a/premake5.lua +++ b/premake5.lua @@ -90,7 +90,6 @@ project "GLFW" filter "system:linux" pic "On" - systemversion "latest" files @@ -178,7 +177,21 @@ project "GLFW" defines { "_GLFW_WIN32", - "_CRT_SECURE_NO_WARNINGS" + "_CRT_SECURE_NO_WARNINGS", + } + + links + { + "gdi32", + "user32", + "kernel32", + "shell32", + "msvcrt" + } + + linkoptions + { + "/NODEFAULTLIB:library" } filter "configurations:Debug" @@ -204,7 +217,7 @@ group "" project "Donut" kind "ConsoleApp" - language "C" + language "C++" staticruntime "on" targetdir ("bin/" .. outputdir .. "/%{prj.name}") @@ -218,7 +231,7 @@ project "Donut" files { "src/**.h", - "src/**.c" + "src/**.cpp" } includedirs @@ -232,7 +245,6 @@ project "Donut" { "GLFW", "GLAD", - "opengl32.lib" } filter "system:windows" @@ -242,6 +254,21 @@ project "Donut" "GLFW_INCLUDE_NONE" } + links + { + "gdi32", + "user32", + "kernel32", + "shell32", + "opengl32", + "msvcrt" + } + + linkoptions + { + "/NODEFAULTLIB:library" + } + filter "configurations:Debug" defines "DONUT_DEBUG" runtime "Debug" diff --git a/src/core/window.cpp b/src/core/window.cpp new file mode 100644 index 0000000..3a6ba2c --- /dev/null +++ b/src/core/window.cpp @@ -0,0 +1,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); + } +} diff --git a/src/core/window.h b/src/core/window.h new file mode 100644 index 0000000..5f0e36e --- /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 should_close() const; + void on_update() const; + private: + GLFWwindow* m_window; + + std::string m_title; + int m_width; + int m_height; + bool m_is_closed; + }; +} 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..c6bbd94 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,11 @@ +#include "core/window.h" + +int main() +{ + Donut::Window window("Donut", 1280, 720); + + while (!window.should_close()) + { + window.on_update(); + } +} |
