fix(close #11): Fix window resizing
This commit is contained in:
parent
a337c9394b
commit
0ced6c452f
@ -6,13 +6,21 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <Renderer.h>
|
#include <Renderer.h>
|
||||||
|
|
||||||
|
struct WindowSize
|
||||||
|
{
|
||||||
|
int Width, Height;
|
||||||
|
|
||||||
|
WindowSize(): Width(0), Height(0){}
|
||||||
|
WindowSize(int width, int height): Width(width), Height(height){}
|
||||||
|
};
|
||||||
|
|
||||||
struct WindowData
|
struct WindowData
|
||||||
{
|
{
|
||||||
std::string Title;
|
std::string Title;
|
||||||
int Width, Height;
|
WindowSize Size;
|
||||||
|
|
||||||
WindowData(): Title("Ferx Engine"), Width(900), Height(600){}
|
WindowData(): Title("Ferx Engine"), Size(900, 600){}
|
||||||
WindowData(const std::string& title, int width, int height): Title(title), Width(width), Height(height){};
|
WindowData(const std::string& title, int width, int height): Title(title), Size(width, height){};
|
||||||
};
|
};
|
||||||
|
|
||||||
class Window
|
class Window
|
||||||
@ -24,16 +32,14 @@ public:
|
|||||||
|
|
||||||
static Window Create();
|
static Window Create();
|
||||||
static Window Create(const std::string& title, int width, int height);
|
static Window Create(const std::string& title, int width, int height);
|
||||||
static void FramebufferSizeCallback(GLFWwindow* window, int width, int height);
|
|
||||||
|
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
GLFWwindow* GetWindow() const;
|
GLFWwindow* GetWindow() const;
|
||||||
const std::string& GetTitle() const;
|
const std::string& GetTitle() const;
|
||||||
int GetWidth() const;
|
WindowSize GetSize();
|
||||||
int GetHeight() const;
|
|
||||||
|
|
||||||
void Shutdown();
|
void Shutdown() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GLFWwindow* m_Window{};
|
GLFWwindow* m_Window{};
|
||||||
|
@ -20,6 +20,15 @@ void Renderer::Init()
|
|||||||
|
|
||||||
LoadShaders();
|
LoadShaders();
|
||||||
SetupBuffers();
|
SetupBuffers();
|
||||||
|
|
||||||
|
glfwSetWindowSizeCallback(Engine::Get().GetWindow().GetWindow(), [](GLFWwindow* window, int width, int height)
|
||||||
|
{
|
||||||
|
SetupBuffers();
|
||||||
|
});
|
||||||
|
glfwSetFramebufferSizeCallback(Engine::Get().GetWindow().GetWindow(), [](GLFWwindow* window, int width, int height)
|
||||||
|
{
|
||||||
|
glViewport(0, 0, width, height);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RendererData Renderer::GetData()
|
RendererData Renderer::GetData()
|
||||||
@ -41,7 +50,8 @@ void Renderer::SetupBuffers()
|
|||||||
};
|
};
|
||||||
|
|
||||||
s_Data.m_FBO = new FrameBuffer();
|
s_Data.m_FBO = new FrameBuffer();
|
||||||
s_Data.m_FBO->AttachTexture(Engine::Get().GetWindow().GetWidth(), Engine::Get().GetWindow().GetHeight());
|
WindowSize windowSize = Engine::Get().GetWindow().GetSize();
|
||||||
|
s_Data.m_FBO->AttachTexture(windowSize.Width, windowSize.Height);
|
||||||
|
|
||||||
s_Data.m_VAO = new VertexArray();
|
s_Data.m_VAO = new VertexArray();
|
||||||
s_Data.m_VBO = new VertexBuffer();
|
s_Data.m_VBO = new VertexBuffer();
|
||||||
|
@ -29,7 +29,7 @@ void Window::Init()
|
|||||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||||
|
|
||||||
m_Window = glfwCreateWindow(m_Data.Width, m_Data.Height, m_Data.Title.c_str(), nullptr, nullptr);
|
m_Window = glfwCreateWindow(m_Data.Size.Width, m_Data.Size.Height, m_Data.Title.c_str(), nullptr, nullptr);
|
||||||
if (!m_Window) {
|
if (!m_Window) {
|
||||||
std::cerr << "Failed to create GLFW window" << std::endl;
|
std::cerr << "Failed to create GLFW window" << std::endl;
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
@ -37,8 +37,6 @@ void Window::Init()
|
|||||||
}
|
}
|
||||||
|
|
||||||
glfwMakeContextCurrent(m_Window);
|
glfwMakeContextCurrent(m_Window);
|
||||||
|
|
||||||
glfwSetFramebufferSizeCallback(m_Window, FramebufferSizeCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Window Window::Create()
|
Window Window::Create()
|
||||||
@ -51,11 +49,6 @@ Window Window::Create(const std::string& title, int width, int height)
|
|||||||
return Window{title, width, height};
|
return Window{title, width, height};
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::FramebufferSizeCallback(GLFWwindow* window, int width, int height)
|
|
||||||
{
|
|
||||||
glViewport(0, 0, width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
GLFWwindow* Window::GetWindow() const
|
GLFWwindow* Window::GetWindow() const
|
||||||
{
|
{
|
||||||
return m_Window;
|
return m_Window;
|
||||||
@ -66,18 +59,13 @@ const std::string& Window::GetTitle() const
|
|||||||
return m_Data.Title;
|
return m_Data.Title;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Window::GetWidth() const
|
WindowSize Window::GetSize()
|
||||||
{
|
{
|
||||||
return m_Data.Width;
|
glfwGetWindowSize(m_Window, &m_Data.Size.Width, &m_Data.Size.Height);
|
||||||
|
return m_Data.Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Window::GetHeight() const
|
void Window::Shutdown() const
|
||||||
{
|
|
||||||
return m_Data.Height;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Window::Shutdown()
|
|
||||||
{
|
{
|
||||||
glfwDestroyWindow(m_Window);
|
glfwDestroyWindow(m_Window);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user