添加多模型渲染,添加贴图渲染,添加平行光, 暂时不上传assets
This commit is contained in:
@@ -8,32 +8,46 @@
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace Engine {
|
||||
namespace Engine
|
||||
{
|
||||
void Window::FramebufferResizeCallback(GLFWwindow* window, int width, int height)
|
||||
{
|
||||
auto* self = static_cast<Window*>(glfwGetWindowUserPointer(window));
|
||||
self->m_FramebufferResized = true;
|
||||
}
|
||||
|
||||
Window::Window(const std::string& title, u32 width, u32 height)
|
||||
: m_Width(width), m_Height(height), m_Title(title)
|
||||
{
|
||||
if (!glfwInit()) {
|
||||
if (!glfwInit())
|
||||
{
|
||||
ENGINE_FATAL("glfwInit failed");
|
||||
return;
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
// glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||
|
||||
m_Window = glfwCreateWindow(width, height, title.c_str(), nullptr, nullptr);
|
||||
if (!m_Window) {
|
||||
if (!m_Window)
|
||||
{
|
||||
ENGINE_FATAL("glfwCreateWindow failed");
|
||||
glfwTerminate();
|
||||
return;
|
||||
}
|
||||
|
||||
ENGINE_INFO("Window created: {} ({}x{})", title, width, height);
|
||||
|
||||
// callbacks
|
||||
|
||||
glfwSetWindowUserPointer(m_Window, this);
|
||||
glfwSetFramebufferSizeCallback(m_Window, FramebufferResizeCallback);
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
if (m_Window) {
|
||||
if (m_Window)
|
||||
{
|
||||
glfwDestroyWindow(m_Window);
|
||||
}
|
||||
glfwTerminate();
|
||||
@@ -52,7 +66,8 @@ namespace Engine {
|
||||
vk::SurfaceKHR Window::CreateSurface(vk::Instance instance)
|
||||
{
|
||||
VkSurfaceKHR surface;
|
||||
if (glfwCreateWindowSurface(instance, m_Window, nullptr, &surface) != VK_SUCCESS) {
|
||||
if (glfwCreateWindowSurface(instance, m_Window, nullptr, &surface) != VK_SUCCESS)
|
||||
{
|
||||
ENGINE_FATAL("glfwCreateWindowSurface failed");
|
||||
return nullptr;
|
||||
}
|
||||
@@ -71,4 +86,38 @@ namespace Engine {
|
||||
return std::vector<const char*>(extensions, extensions + count);
|
||||
}
|
||||
|
||||
} // namespace Engine
|
||||
void Window::GetFramebufferSize(int& width, int& height) const
|
||||
{
|
||||
glfwGetFramebufferSize(m_Window, &width, &height);
|
||||
}
|
||||
|
||||
bool Window::IsKeyPressed(int key) const
|
||||
{
|
||||
return glfwGetKey(m_Window, key) == GLFW_PRESS;
|
||||
}
|
||||
|
||||
void Window::GetMouseDelta(float& dx, float& dy)
|
||||
{
|
||||
double mx, my;
|
||||
glfwGetCursorPos(m_Window, &mx, &my);
|
||||
|
||||
static double lastX = mx;
|
||||
static double lastY = my;
|
||||
static bool first = true;
|
||||
|
||||
if (first)
|
||||
{
|
||||
lastX = mx;
|
||||
lastY = my;
|
||||
first = false;
|
||||
dx = dy = 0.0f;
|
||||
return;
|
||||
}
|
||||
|
||||
dx = static_cast<float>(mx - lastX);
|
||||
dy = static_cast<float>(my - lastY);
|
||||
|
||||
lastX = mx;
|
||||
lastY = my;
|
||||
}
|
||||
} // namespace Engine
|
||||
|
||||
Reference in New Issue
Block a user