Added Window
This commit is contained in:
parent
8d633dac01
commit
7998d53c31
7 changed files with 122 additions and 4 deletions
|
@ -26,6 +26,7 @@ project "Engine"
|
|||
"%{prj.location}/src/Engine/",
|
||||
|
||||
(dependenciesdir .. "spdlog/include/"),
|
||||
(dependenciesdir .. "glfw/include/"),
|
||||
}
|
||||
|
||||
links
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Application.h"
|
||||
|
||||
#include "Logger.h"
|
||||
#include "Window.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
|
@ -8,6 +9,8 @@ namespace Light {
|
|||
{
|
||||
Logger::Initialize();
|
||||
|
||||
m_Window = std::unique_ptr<Window>(Window::Create({ "Title", 800u, 600u, false }));
|
||||
|
||||
LT_ENGINE_INFO("Initialized Logger");
|
||||
}
|
||||
|
||||
|
@ -17,7 +20,7 @@ namespace Light {
|
|||
|
||||
void Application::GameLoop()
|
||||
{
|
||||
while (true);
|
||||
while (true) { m_Window->OnUpdate(); }
|
||||
}
|
||||
|
||||
}
|
|
@ -2,17 +2,27 @@
|
|||
|
||||
#include "Base.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Light {
|
||||
|
||||
class Window;
|
||||
|
||||
class Application
|
||||
{
|
||||
private:
|
||||
std::unique_ptr<Window> m_Window = nullptr;
|
||||
|
||||
public:
|
||||
Application();
|
||||
virtual ~Application();
|
||||
|
||||
void GameLoop();
|
||||
|
||||
// To be defined in client project
|
||||
friend Application* CreateApplication();
|
||||
|
||||
protected:
|
||||
Application();
|
||||
};
|
||||
|
||||
Application* CreateApplication();
|
||||
|
||||
}
|
31
Engine/src/Engine/Core/Window.h
Normal file
31
Engine/src/Engine/Core/Window.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Light {
|
||||
|
||||
struct WindowProperties
|
||||
{
|
||||
std::string title;
|
||||
unsigned int width, height;
|
||||
bool vsync;
|
||||
};
|
||||
|
||||
class Window
|
||||
{
|
||||
public:
|
||||
virtual ~Window() = default;
|
||||
|
||||
virtual void OnUpdate() = 0;
|
||||
|
||||
virtual unsigned int GetHeight() = 0;
|
||||
virtual unsigned int GetWidth() = 0;
|
||||
|
||||
virtual inline void* GetNativeHandle() = 0;
|
||||
|
||||
static Window* Create(const WindowProperties& properties);
|
||||
};
|
||||
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#ifdef LT_PLATFORM_WINDOWS
|
||||
|
||||
// To be defined in client project
|
||||
extern Light::Application* Light::CreateApplication();
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
|
41
Engine/src/Engine/Platforms/OS/Windows/wWindow.cpp
Normal file
41
Engine/src/Engine/Platforms/OS/Windows/wWindow.cpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
#include "wWindow.h"
|
||||
|
||||
namespace Light {
|
||||
|
||||
Window* Window::Create(const WindowProperties& properties)
|
||||
{
|
||||
return new wWindow(properties);
|
||||
}
|
||||
|
||||
wWindow::wWindow(const WindowProperties& properties)
|
||||
: m_Properties(properties)
|
||||
{
|
||||
if (!glfwInit()) __debugbreak();
|
||||
|
||||
m_Handle = glfwCreateWindow(properties.width, properties.height, properties.title.c_str(), nullptr, nullptr);
|
||||
|
||||
glfwMakeContextCurrent(m_Handle);
|
||||
}
|
||||
|
||||
wWindow::~wWindow()
|
||||
{
|
||||
glfwDestroyWindow(m_Handle);
|
||||
}
|
||||
|
||||
void wWindow::OnUpdate()
|
||||
{
|
||||
glfwPollEvents();
|
||||
glfwSwapBuffers(m_Handle);
|
||||
}
|
||||
|
||||
unsigned int wWindow::GetWidth()
|
||||
{
|
||||
return m_Properties.width;
|
||||
}
|
||||
|
||||
unsigned int wWindow::GetHeight()
|
||||
{
|
||||
return m_Properties.height;
|
||||
}
|
||||
|
||||
}
|
31
Engine/src/Engine/Platforms/OS/Windows/wWindow.h
Normal file
31
Engine/src/Engine/Platforms/OS/Windows/wWindow.h
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include "Base.h"
|
||||
|
||||
#include "Core/Window.h"
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace Light {
|
||||
|
||||
class wWindow : public Window
|
||||
{
|
||||
private:
|
||||
GLFWwindow* m_Handle = nullptr;
|
||||
WindowProperties m_Properties;
|
||||
public:
|
||||
wWindow(const WindowProperties& properties);
|
||||
|
||||
~wWindow();
|
||||
|
||||
virtual void OnUpdate() override;
|
||||
|
||||
virtual unsigned int GetWidth() override;
|
||||
virtual unsigned int GetHeight() override;
|
||||
|
||||
virtual inline void* GetNativeHandle() override { return m_Handle; }
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue