initial commit
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#ifndef HYDRARENDERSETTINGS
|
||||
#define HYDRARENDERSETTINGS
|
||||
|
||||
struct HydraRenderSettings
|
||||
{
|
||||
int DisplayWidth = 1900;
|
||||
int DisplayHeight = 1080;
|
||||
|
||||
int ViewportWidth = 1900;
|
||||
int ViewportHeight = 1080;
|
||||
|
||||
int ColorDepth = 32;
|
||||
int ZBits = 24;
|
||||
int AlphaBits = 16;
|
||||
|
||||
|
||||
float Near = 0.3f;
|
||||
float Far = 10000.0f;
|
||||
|
||||
float FOV = 60.0f;
|
||||
};
|
||||
#endif /* HYDRARENDERSETTINGS */
|
||||
@@ -0,0 +1,137 @@
|
||||
#include "HydraWindowManager.h"
|
||||
#include "../HydraDefines.h"
|
||||
// #include "../UI/HydraUIManager.h"
|
||||
#include "../engine/HydraEngine.h"
|
||||
|
||||
std::vector<HydraKeyPressStuct> HydraWindowManager::m_key_presses;
|
||||
std::queue<HydraMouseMoveStruct> HydraWindowManager::m_mouse_moves;
|
||||
glm::vec2 HydraWindowManager::m_mouse_position;
|
||||
std::mutex HydraWindowManager::m_mouse_pos_mutex;
|
||||
|
||||
void HydraWindowManager::key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (action == GLFW_PRESS)
|
||||
{
|
||||
m_key_presses.push_back(HydraKeyPressStuct(key, KEY_PRESS_ACTIONS::HYDRA_KEY_PRESSED));
|
||||
}
|
||||
else if (action == GLFW_RELEASE)
|
||||
{
|
||||
m_key_presses.push_back(HydraKeyPressStuct(key, KEY_PRESS_ACTIONS::HYDRA_KEY_RELEASED));
|
||||
}
|
||||
}
|
||||
|
||||
bool HydraWindowManager::CreateRenderWindow(std::string title, HydraRenderSettings renderSettings)
|
||||
{
|
||||
/* Init GLFW */
|
||||
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
GLFWmonitor *monitor = glfwGetPrimaryMonitor();
|
||||
if (monitor)
|
||||
{
|
||||
const GLFWvidmode *mode = glfwGetVideoMode(monitor);
|
||||
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
|
||||
m_window = glfwCreateWindow(renderSettings.ViewportWidth, renderSettings.DisplayHeight, "Hydra", NULL, NULL);
|
||||
if (!m_window)
|
||||
{
|
||||
glfwTerminate();
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// glfwSetWindowMonitor(m_window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
|
||||
}
|
||||
else
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// glfwSetWindowAspectRatio(m_window, 1, 1);
|
||||
|
||||
glfwSetKeyCallback(m_window, key_callback);
|
||||
glfwSetMouseButtonCallback(m_window, mouse_button_callback);
|
||||
glfwSetCursorPosCallback(m_window, cursor_position_callback);
|
||||
|
||||
glfwMakeContextCurrent(m_window);
|
||||
|
||||
// VSYNC
|
||||
glfwSwapInterval(0);
|
||||
glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
|
||||
if (glfwRawMouseMotionSupported())
|
||||
{
|
||||
glfwSetInputMode(m_window, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
|
||||
}
|
||||
|
||||
// GetEngine()->UIManager()->InitialsGUI(m_window);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void HydraWindowManager::mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
|
||||
{
|
||||
if (button != GLFW_MOUSE_BUTTON_LEFT)
|
||||
return;
|
||||
}
|
||||
|
||||
void HydraWindowManager::cursor_position_callback(GLFWwindow *window, double x, double y)
|
||||
{
|
||||
SetMousePosition(glm::vec2((float)x, (float)y));
|
||||
m_mouse_moves.push(HydraMouseMoveStruct((int)x, (int)y));
|
||||
}
|
||||
|
||||
void HydraWindowManager::SetMousePosition(glm::vec2 mouse_pos)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mouse_pos_mutex);
|
||||
m_mouse_position = mouse_pos;
|
||||
}
|
||||
|
||||
bool HydraWindowManager::HandleMessages()
|
||||
{
|
||||
glfwPollEvents();
|
||||
return false;
|
||||
}
|
||||
|
||||
void HydraWindowManager::Shutdown()
|
||||
{
|
||||
// GetEngine()->UIManager()->ShutdownGUI();
|
||||
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
bool HydraWindowManager::GetKeyPress(HydraKeyPressStuct &key_press)
|
||||
{
|
||||
if (!m_key_presses.empty())
|
||||
{
|
||||
key_press = m_key_presses.back();
|
||||
m_key_presses.pop_back();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool HydraWindowManager::GetMouseMove(HydraMouseMoveStruct &mouse_move)
|
||||
{
|
||||
if (!m_mouse_moves.empty())
|
||||
{
|
||||
mouse_move = m_mouse_moves.front();
|
||||
m_mouse_moves.pop();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
glm::vec2 HydraWindowManager::GetMousePosition()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mouse_pos_mutex);
|
||||
return m_mouse_position;
|
||||
}
|
||||
|
||||
void HydraWindowManager::Swap()
|
||||
{
|
||||
glfwMakeContextCurrent(m_window);
|
||||
// GetEngine()->UIManager()->BeginGUIRender();
|
||||
// GetEngine()->UIManager()->RenderGUI();
|
||||
// GetEngine()->UIManager()->EndGUIRender();
|
||||
|
||||
glfwSwapBuffers(m_window);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#ifndef HYDRAWINDOWMANAGER
|
||||
#define HYDRAWINDOWMANAGER
|
||||
|
||||
#include "../engine/HydraObject.h"
|
||||
#include "HydraRenderSettings.h"
|
||||
#include "../GlewIncludes.h"
|
||||
#include <GLMIncludes.h>
|
||||
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
|
||||
class HydraWindowManager : public HydraObject
|
||||
{
|
||||
private:
|
||||
static std::mutex m_mouse_pos_mutex;
|
||||
static std::vector<HydraKeyPressStuct> m_key_presses;
|
||||
static std::queue<HydraMouseMoveStruct> m_mouse_moves;
|
||||
static glm::vec2 m_mouse_position;
|
||||
|
||||
GLFWwindow* m_window = nullptr;
|
||||
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods);
|
||||
|
||||
static void cursor_position_callback(GLFWwindow* window, double x, double y);
|
||||
static void mouse_button_callback(GLFWwindow* window, int button, int action, int mods);
|
||||
|
||||
static void SetMousePosition(glm::vec2 mouse_pos);
|
||||
public:
|
||||
bool CreateRenderWindow(std::string title, HydraRenderSettings renderSettings);
|
||||
// void ExitFullScreen() {};
|
||||
// void SetFullScreen() {};
|
||||
// void* GetManagedDC() { return nullptr; }
|
||||
bool HandleMessages();
|
||||
void Shutdown();
|
||||
|
||||
static bool GetKeyPress(HydraKeyPressStuct& key_press);
|
||||
static bool GetMouseMove(HydraMouseMoveStruct& mouse_move);
|
||||
static glm::vec2 GetMousePosition();
|
||||
GLFWwindow* const GetWindow() {return m_window;}
|
||||
void Swap();
|
||||
};
|
||||
|
||||
|
||||
#endif /* HYDRAWINDOWMANAGER */
|
||||
Reference in New Issue
Block a user