window refactor 50%

This commit is contained in:
Ben Kyd
2023-04-24 00:12:18 +01:00
parent b4e7a51400
commit 2e072d23f1
3 changed files with 27 additions and 47 deletions

View File

@@ -39,6 +39,5 @@ GLuint shader_get_uniform(std::unique_ptr<Shader>& shader, const std::string& un
void shader_use(std::unique_ptr<Shader>& shader);
void shader_unuse(std::unique_ptr<Shader>& shader);
}

View File

@@ -4,21 +4,26 @@
#include "yolo/yolo.hpp"
using namespace inferno;
using namespace inferno::graphics;
Window::Window() {}
static WINDOW_MODE WinMode = WINDOW_MODE::WIN_MODE_DEFAULT;
static KeyCallback KeyCallback = nullptr;
static int Width, Height;
static const char* GlslVersion;
static GLFWwindow* Gindow;
Window::~Window() {
static void glfwErrorCallback(int error, const char* description);
void window_cleanup() {
shutdownImGui();
shutdownGLFW();
}
void Window::init(std::string title, int width, int height) {
this->width = width;
this->height = height;
void window_create(std::string title, int width, int height) {
Width = width;
Height = height;
setupGLFW(title);
glfwSetKeyCallback(getGLFWWindow(), glfwKeyCallback);
setupImGui();
}

View File

@@ -7,7 +7,7 @@
#define WINDOW_FLAGS ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_MenuBar | ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoCollapse
namespace inferno {
namespace inferno::graphics {
typedef void (*KeyCallback)(int key, int scan, int action, int mod);
typedef void (*MouseCallback)(double x, double y);
@@ -18,48 +18,24 @@ enum WINDOW_MODE
WIN_MODE_FPS,
};
class Window : public helpers::Singleton<Window>
{
public:
Window();
~Window();
void window_create(std::string title, int width, int height);
void window_cleanup();
void init(std::string title, int width, int height);
void window_set_title(std::string title);
bool newFrame();
void render();
void window_set_size(int w, int h);
void window_set_pos(int x, int y);
glm::vec2 window_get_size();
void window_get_pos(int& x, int& y);
void setTitle(std::string title);
void setSize(int w, int h);
void setPos(int x, int y);
GLFWwindow* window_get_glfw_window();
void window_set_fps_mode();
glm::vec2 getSize();
void getPos(int& x, int& y);
GLFWwindow* getGLFWWindow() { return window; }
void window_set_key_callback(KeyCallback callback);
KeyCallback window_get_key_callback();
void setFPSMode();
void setKeyCallback(KeyCallback callback);
KeyCallback getKeyCallback();
private:
WINDOW_MODE mWinMode = WIN_MODE_DEFAULT;
private:
void setupGLFW(std::string title);
void setupImGui();
void shutdownImGui();
void shutdownGLFW();
static void glfwKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
KeyCallback mKeyCallback = nullptr;
private:
static void glfwErrorCallback(int error, const char* description);
int width, height;
const char* glslVersion;
GLFWwindow* window;
};
bool window_new_frame();
void window_render();
}