|
|
@ -5,10 +5,11 @@ |
|
|
|
#include "inferno/event/applicationevent.h" |
|
|
|
#include "inferno/event/applicationevent.h" |
|
|
|
#include "inferno/event/keyevent.h" |
|
|
|
#include "inferno/event/keyevent.h" |
|
|
|
#include "inferno/event/mouseevent.h" |
|
|
|
#include "inferno/event/mouseevent.h" |
|
|
|
#include "inferno/keycodes.h" |
|
|
|
|
|
|
|
#include "inferno/io/input.h" |
|
|
|
#include "inferno/io/input.h" |
|
|
|
#include "inferno/io/log.h" |
|
|
|
#include "inferno/io/log.h" |
|
|
|
|
|
|
|
#include "inferno/keycodes.h" |
|
|
|
#include "inferno/render/context.h" |
|
|
|
#include "inferno/render/context.h" |
|
|
|
|
|
|
|
#include "inferno/render/renderer.h" |
|
|
|
#include "inferno/settings.h" |
|
|
|
#include "inferno/settings.h" |
|
|
|
#include "inferno/window.h" |
|
|
|
#include "inferno/window.h" |
|
|
|
|
|
|
|
|
|
|
@ -41,6 +42,7 @@ namespace Inferno { |
|
|
|
std::string title = m_properties.title; |
|
|
|
std::string title = m_properties.title; |
|
|
|
unsigned int width = m_properties.width; |
|
|
|
unsigned int width = m_properties.width; |
|
|
|
unsigned int height = m_properties.height; |
|
|
|
unsigned int height = m_properties.height; |
|
|
|
|
|
|
|
bool vsync = m_properties.vsync; |
|
|
|
|
|
|
|
|
|
|
|
// Only init once
|
|
|
|
// Only init once
|
|
|
|
if (s_windowCount == 0) { |
|
|
|
if (s_windowCount == 0) { |
|
|
@ -68,8 +70,9 @@ namespace Inferno { |
|
|
|
m_context = std::make_shared<Context>(m_window); |
|
|
|
m_context = std::make_shared<Context>(m_window); |
|
|
|
m_context->initialize(); |
|
|
|
m_context->initialize(); |
|
|
|
|
|
|
|
|
|
|
|
// Capture cursor and hide it
|
|
|
|
// Set vsync, viewport
|
|
|
|
// glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
|
|
|
setVSync(vsync); |
|
|
|
|
|
|
|
RenderCommand::setViewport(0, 0, width, height); |
|
|
|
|
|
|
|
|
|
|
|
// Error callback
|
|
|
|
// Error callback
|
|
|
|
glfwSetErrorCallback([](int error, const char* description) { |
|
|
|
glfwSetErrorCallback([](int error, const char* description) { |
|
|
@ -160,18 +163,29 @@ namespace Inferno { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Window::destroy() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_context->destroy(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
glfwDestroyWindow(m_window); |
|
|
|
|
|
|
|
s_windowCount--; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (s_windowCount == 0) { |
|
|
|
|
|
|
|
glfwTerminate(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Window::update() |
|
|
|
void Window::update() |
|
|
|
{ |
|
|
|
{ |
|
|
|
glfwPollEvents(); |
|
|
|
glfwPollEvents(); |
|
|
|
|
|
|
|
|
|
|
|
// Lock mouse in window
|
|
|
|
// Capture cursor in window and hide it
|
|
|
|
if (Input::isKeyPressed(keyCode("GLFW_KEY_LEFT_SUPER"))) { |
|
|
|
if (!Input::isKeyPressed(keyCode("GLFW_KEY_LEFT_SUPER"))) { |
|
|
|
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); |
|
|
|
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); |
|
|
|
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Window::render() |
|
|
|
void Window::render() |
|
|
@ -179,19 +193,9 @@ namespace Inferno { |
|
|
|
m_context->render(); |
|
|
|
m_context->render(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Window::destroy() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
glfwDestroyWindow(m_window); |
|
|
|
|
|
|
|
s_windowCount--; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (s_windowCount == 0) { |
|
|
|
|
|
|
|
glfwTerminate(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
void Window::setWindowMonitor() |
|
|
|
void Window::setWindowMonitor() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
GLFWmonitor* monitor = glfwGetPrimaryMonitor(); |
|
|
|
GLFWmonitor* monitor = glfwGetPrimaryMonitor(); |
|
|
|
int xPos = 0; |
|
|
|
int xPos = 0; |
|
|
@ -222,8 +226,10 @@ namespace Inferno { |
|
|
|
glfwSetWindowMonitor(m_window, monitor, xPos, yPos, width, height, refresh); |
|
|
|
glfwSetWindowMonitor(m_window, monitor, xPos, yPos, width, height, refresh); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Window::shouldClose() const { |
|
|
|
void Window::setVSync(bool enabled) |
|
|
|
return glfwWindowShouldClose(m_window); |
|
|
|
{ |
|
|
|
|
|
|
|
enabled ? glfwSwapInterval(GL_TRUE) : glfwSwapInterval(GL_FALSE); |
|
|
|
|
|
|
|
m_properties.vsync = enabled; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Window::setShouldClose(bool close) const |
|
|
|
void Window::setShouldClose(bool close) const |
|
|
@ -231,4 +237,8 @@ namespace Inferno { |
|
|
|
glfwSetWindowShouldClose(m_window, close ? GL_TRUE : GL_FALSE); |
|
|
|
glfwSetWindowShouldClose(m_window, close ? GL_TRUE : GL_FALSE); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Window::shouldClose() const { |
|
|
|
|
|
|
|
return glfwWindowShouldClose(m_window); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|