parent
							
								
									2c00c4f90b
								
							
						
					
					
						commit
						4795e2090d
					
				
				 2 changed files with 105 additions and 0 deletions
			
			
		| @ -0,0 +1,68 @@ | |||||||
|  | #include "win_glfw.h" | ||||||
|  | namespace Bk { | ||||||
|  |     std::unique_ptr<Window> Window::create_window(const WindowPros& props) | ||||||
|  |     { | ||||||
|  |         return std::unique_ptr<Window>(new Plaform::WinGLFW(props)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     namespace Plaform { | ||||||
|  |         static uint p_glfw_initialized = 0; | ||||||
|  | 
 | ||||||
|  |         static void glfw_error_callback(int error, const char* description) 
 | ||||||
|  |         { | ||||||
|  |             BK_CORE_CRITICAL("GLFW Error ({0}) {1}", error, description); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         WinGLFW::WinGLFW(const WindowPros& props) 
 | ||||||
|  |         { | ||||||
|  |             p_data.title = props.title; | ||||||
|  |             p_data.width = props.width; | ||||||
|  |             p_data.height = props.height; | ||||||
|  | 
 | ||||||
|  |             BK_CORE_INFO("Creating window : {0} ({1}, {2})", props.title, props.width, props.height); 
 | ||||||
|  |             if (!p_glfw_initialized++) 
 | ||||||
|  |             { | ||||||
|  |                 int success = glfwInit(); | ||||||
|  |                 BK_MSG_ASSERT(success, "Couldn't initialize glfw!") | ||||||
|  |                 glfwSetErrorCallback(glfw_error_callback); | ||||||
|  |             } | ||||||
|  |             p_window = glfwCreateWindow((int)props.width, (int)props.height, props.title.c_str(), nullptr, nullptr); | ||||||
|  |             glfwMakeContextCurrent(p_window); | ||||||
|  |             glfwSetWindowUserPointer(p_window, &p_data); | ||||||
|  |             set_vsync(true); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         WinGLFW::~WinGLFW() 
 | ||||||
|  |         { | ||||||
|  |             shutdown(); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         void WinGLFW::on_update()  
 | ||||||
|  |         { | ||||||
|  |             glfwPollEvents(); | ||||||
|  |             glfwSwapBuffers(p_window); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         void WinGLFW::set_event_callback(const EventCallback callback)  
 | ||||||
|  |         { | ||||||
|  |             p_data.callback = callback; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         void WinGLFW::set_vsync(bool enable)  
 | ||||||
|  |         { | ||||||
|  |             if (enable) { glfwSwapInterval(1); } | ||||||
|  |             else { glfwSwapInterval(0); } | ||||||
|  |             p_data.vsync = enable; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         bool WinGLFW::is_vsync() const  
 | ||||||
|  |         { | ||||||
|  |             return p_data.vsync; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         void WinGLFW::shutdown() | ||||||
|  |         { | ||||||
|  |             glfwDestroyWindow(p_window); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,37 @@ | |||||||
|  | #pragma once | ||||||
|  | #include <bkpch.h> | ||||||
|  | #include <bakara/core/window.h> | ||||||
|  | #include <GLFW/glfw3.h> | ||||||
|  | 
 | ||||||
|  | namespace Bk::Plaform { | ||||||
|  |     class WinGLFW : public Window | ||||||
|  |     { | ||||||
|  |         public: | ||||||
|  |             WinGLFW(const WindowPros& props); | ||||||
|  |             virtual ~WinGLFW(); | ||||||
|  | 
 | ||||||
|  |             inline uint get_width() const override { return p_data.width; } | ||||||
|  |             inline uint get_height() const override { return p_data.height; } | ||||||
|  |         
 | ||||||
|  |             void on_update() override; | ||||||
|  |             void set_event_callback(const EventCallback callback) override; | ||||||
|  | 
 | ||||||
|  |             void set_vsync(bool enable) override; | ||||||
|  |             bool is_vsync() const override; | ||||||
|  |         
 | ||||||
|  |         private: | ||||||
|  |             GLFWwindow* p_window; | ||||||
|  | 
 | ||||||
|  |             struct WindowData 
 | ||||||
|  |             { | ||||||
|  |                 std::string title; | ||||||
|  |                 uint width; | ||||||
|  |                 uint height; | ||||||
|  |                 bool vsync; | ||||||
|  |                 EventCallback callback; | ||||||
|  |             }; | ||||||
|  |             WindowData p_data; | ||||||
|  |             
 | ||||||
|  |             void shutdown(); | ||||||
|  |     }; | ||||||
|  | } | ||||||
					Loading…
					
					
				
		Reference in New Issue