diff options
| author | Mel <einebeere@gmail.com> | 2022-10-01 05:12:50 +0200 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2022-10-01 05:13:05 +0200 |
| commit | e2234b4afebb266878435d10267e7b162b1fe984 (patch) | |
| tree | a582ab01a9a95a3dfd199702315d3f43c6b5b046 /src/Window.cpp | |
| download | meowcraft-e2234b4afebb266878435d10267e7b162b1fe984.tar.zst meowcraft-e2234b4afebb266878435d10267e7b162b1fe984.zip | |
Setup window and GL functions
Diffstat (limited to 'src/Window.cpp')
| -rw-r--r-- | src/Window.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/Window.cpp b/src/Window.cpp new file mode 100644 index 0000000..8bb8580 --- /dev/null +++ b/src/Window.cpp @@ -0,0 +1,45 @@ +#include <stdexcept> +#include "Window.hpp" + +namespace MC { + +Window::Window(const char *title, uint32_t width, uint32_t height) { + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + + m_window = glfwCreateWindow(width, height, title, nullptr, nullptr); + if (m_window == nullptr) { + throw std::runtime_error("Failed to create window."); + } + + glfwMakeContextCurrent(m_window); +} + +Window::~Window() { + glfwDestroyWindow(m_window); +} + +bool Window::should_close() { + return glfwWindowShouldClose(m_window); +} + +GLFWwindow* Window::get() { + return m_window; +} + +void Window::close() { + glfwSetWindowShouldClose(m_window, true); +} + +bool Window::key(int key, int type) { + return (glfwGetKey(m_window, key) == type); +} + +void Window::start_frame() { + glfwSwapBuffers(m_window); + glfwPollEvents(); +} + +} \ No newline at end of file |
