switching workstation
This commit is contained in:
111
src/window.cpp
111
src/window.cpp
@@ -6,80 +6,56 @@
|
||||
|
||||
using namespace inferno;
|
||||
|
||||
Window::Window()
|
||||
{
|
||||
Window::Window() {}
|
||||
|
||||
}
|
||||
|
||||
Window::~Window()
|
||||
{
|
||||
Window::~Window() {
|
||||
shutdownImGui();
|
||||
shutdownGLFW();
|
||||
shutdownGLFW();
|
||||
}
|
||||
|
||||
void Window::init(std::string title, int width, int height)
|
||||
{
|
||||
void Window::init(std::string title, int width, int height) {
|
||||
this->width = width;
|
||||
this->height = height;
|
||||
setupGLFW(title);
|
||||
|
||||
glfwSetKeyCallback(getGLFWWindow(), glfwKeyCallback);
|
||||
|
||||
setupImGui();
|
||||
}
|
||||
|
||||
void Window::setTitle(std::string title)
|
||||
{
|
||||
void Window::setTitle(std::string title) {
|
||||
glfwSetWindowTitle(window, title.c_str());
|
||||
}
|
||||
|
||||
void Window::setSize(int w, int h)
|
||||
{
|
||||
void Window::setSize(int w, int h) {
|
||||
width = w;
|
||||
height = h;
|
||||
glfwSetWindowSize(window, width, height);
|
||||
}
|
||||
|
||||
void Window::setPos(int x, int y)
|
||||
{
|
||||
glfwSetWindowPos(window, x, y);
|
||||
}
|
||||
void Window::setPos(int x, int y) { glfwSetWindowPos(window, x, y); }
|
||||
|
||||
glm::vec2 Window::getSize()
|
||||
{
|
||||
return {width, height};
|
||||
}
|
||||
glm::vec2 Window::getSize() { return {width, height}; }
|
||||
|
||||
void Window::getPos(int& x, int& y)
|
||||
{
|
||||
glfwGetWindowPos(window, &x, &y);
|
||||
}
|
||||
void Window::getPos(int &x, int &y) { glfwGetWindowPos(window, &x, &y); }
|
||||
|
||||
void Window::setFPSMode()
|
||||
{
|
||||
void Window::setFPSMode() {
|
||||
mWinMode = WIN_MODE_FPS;
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
}
|
||||
|
||||
void Window::setKeyCallback(KeyCallback callback)
|
||||
{
|
||||
mKeyCallback = callback;
|
||||
}
|
||||
void Window::setKeyCallback(KeyCallback callback) { mKeyCallback = callback; }
|
||||
|
||||
KeyCallback Window::getKeyCallback()
|
||||
{
|
||||
return mKeyCallback;
|
||||
}
|
||||
KeyCallback Window::getKeyCallback() { return mKeyCallback; }
|
||||
|
||||
bool Window::newFrame()
|
||||
{
|
||||
bool Window::newFrame() {
|
||||
glfwPollEvents();
|
||||
if (mWinMode == WIN_MODE_FPS)
|
||||
{
|
||||
if (mWinMode == WIN_MODE_FPS) {
|
||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
glfwSetCursorPos(window, (double)width / 2, (double)height / 2);
|
||||
}
|
||||
if (glfwWindowShouldClose(window)) { return false; }
|
||||
if (glfwWindowShouldClose(window)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
glfwGetWindowSize(window, &width, &height);
|
||||
|
||||
@@ -97,8 +73,7 @@ bool Window::newFrame()
|
||||
return true;
|
||||
}
|
||||
|
||||
void Window::render()
|
||||
{
|
||||
void Window::render() {
|
||||
ImGui::End();
|
||||
ImGui::Render();
|
||||
auto io = ImGui::GetIO();
|
||||
@@ -108,10 +83,10 @@ void Window::render()
|
||||
ImGui::UpdatePlatformWindows();
|
||||
}
|
||||
|
||||
void Window::setupGLFW(std::string title)
|
||||
{
|
||||
void Window::setupGLFW(std::string title) {
|
||||
glfwSetErrorCallback(glfwErrorCallback);
|
||||
if (!glfwInit()) throw std::runtime_error("Failed to initialize GLFW");
|
||||
if (!glfwInit())
|
||||
throw std::runtime_error("Failed to initialize GLFW");
|
||||
|
||||
// Decide GL+GLSL versions
|
||||
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||
@@ -125,27 +100,27 @@ void Window::setupGLFW(std::string title)
|
||||
glslVersion = "#version 150";
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac
|
||||
#else
|
||||
// GL 4.5 + GLSL 450
|
||||
glslVersion = "#version 450";
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only
|
||||
#endif
|
||||
|
||||
// Create window with graphics context
|
||||
window = glfwCreateWindow(1280, 720, title.c_str(), NULL, NULL);
|
||||
if (window == NULL) throw std::runtime_error("Could not create window");
|
||||
if (window == NULL)
|
||||
throw std::runtime_error("Could not create window");
|
||||
glfwMakeContextCurrent(window);
|
||||
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||
glfwSwapInterval(1); // Enable vsync
|
||||
}
|
||||
|
||||
void Window::setupImGui()
|
||||
{
|
||||
void Window::setupImGui() {
|
||||
// Setup Dear ImGui context
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGui::CreateContext();
|
||||
@@ -153,40 +128,42 @@ void Window::setupImGui()
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T WORK AS EXPECTED. DON'T USE IN USER APP!
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
(void)io;
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking
|
||||
io.ConfigFlags |=
|
||||
ImGuiConfigFlags_DpiEnableScaleFonts; // FIXME-DPI: THIS CURRENTLY DOESN'T
|
||||
// WORK AS EXPECTED. DON'T USE IN
|
||||
// USER APP!
|
||||
io.ConfigFlags |= ImGuiConfigFlags_DpiEnableScaleViewports; // FIXME-DPI
|
||||
// io.ConfigDockingWithShift = true;
|
||||
// io.ConfigDockingWithShift
|
||||
// = true;
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
// Setup Platform/Renderer backends
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init(glslVersion);
|
||||
|
||||
SetupImGuiStyle2();
|
||||
}
|
||||
|
||||
void Window::shutdownImGui()
|
||||
{
|
||||
void Window::shutdownImGui() {
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
}
|
||||
|
||||
void Window::shutdownGLFW()
|
||||
{
|
||||
void Window::shutdownGLFW() {
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
void Window::glfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (Window::GetInstance().getKeyCallback() != nullptr)
|
||||
{
|
||||
void Window::glfwKeyCallback(GLFWwindow *window, int key, int scancode,
|
||||
int action, int mods) {
|
||||
if (Window::GetInstance().getKeyCallback() != nullptr) {
|
||||
Window::GetInstance().getKeyCallback()(key, scancode, action, mods);
|
||||
}
|
||||
}
|
||||
|
||||
void Window::glfwErrorCallback(int error, const char* description) {
|
||||
void Window::glfwErrorCallback(int error, const char *description) {
|
||||
yolo::error("[GLFW {}] {}", error, description);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user