Fix coding standard

This commit is contained in:
rexy712 2020-08-15 16:20:16 -07:00
parent 6211f7fc62
commit 82f63bc13c
2 changed files with 40 additions and 42 deletions

View File

@ -12,36 +12,35 @@ class GLFWwindow;
class render_manager
{
private:
void (*m_windowCloseCallback)(void);
void (*m_inputHandler)(GLFWwindow* window, int key, int scancode, int action, int mods);
GLFWwindow* m_mainWindow;
using close_callback = void(*)(void);
using input_callback = void(*)(GLFWwindow*, int, int, int, int);
close_callback m_window_close_callback;
input_callback m_input_handler;
GLFWwindow* m_main_window;
public:
enum GLFW_ERROR
{
GLFW_OK,
GLFW_CONTEXT_ERROR,
GLFW_WINDOW_ERROR,
GLFW_INIT_ERROR,
enum RENDERER_ERROR{
RENDERER_OK,
RENDERER_CONTEXT_ERROR,
RENDERER_WINDOW_ERROR,
RENDERER_INIT_ERROR,
};
render_manager (render_manager&) = delete;
render_manager (render_manager&&) = delete;
render_manager();
GLFW_ERROR init(int width, int height, const char* title); // Sets up the OpenGL environment
RENDERER_ERROR init(int width, int height, const char* title); // Sets up the OpenGL environment
void update(); // Update the GL context and draw new frame
void request_exit();
template <typename T>
void handle_window_close_event(T handle){
m_windowCloseCallback = handle;
void handle_window_close_event(close_callback handle){
m_window_close_callback = handle;
}
template <typename T>
void handle_keypress_event(T handle){
m_inputHandler = handle;
glfwSetKeyCallback(m_mainWindow, m_inputHandler);
void handle_keypress_event(input_callback handle){
m_input_handler = handle;
glfwSetKeyCallback(m_main_window, m_input_handler);
}
};

View File

@ -12,50 +12,49 @@ namespace
render_manager::render_manager() :
m_windowCloseCallback (nullptr),
m_inputHandler (nullptr),
m_mainWindow (nullptr)
{}
m_window_close_callback (nullptr),
m_input_handler (nullptr),
m_main_window (nullptr){}
render_manager::GLFW_ERROR render_manager::init (int width, int height, const char* title){
render_manager::RENDERER_ERROR render_manager::init (int width, int height, const char* title){
if (!glfwInit()) {
fprintf(stdout, "[EE] failed to initialize GLFW.\n");
return GLFW_INIT_ERROR;
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
m_mainWindow = glfwCreateWindow(width, height, title, nullptr, nullptr);
if (!m_mainWindow) {
fprintf (stdout, "[EE] Could not create window\n");
return GLFW_WINDOW_ERROR;
fprintf(stdout, "[EE] failed to initialize GLFW.\n");
return RENDERER_INIT_ERROR;
}
glfwMakeContextCurrent(m_mainWindow);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
m_main_window = glfwCreateWindow(width, height, title, nullptr, nullptr);
if (!m_main_window) {
fprintf (stdout, "[EE] Could not create window\n");
return RENDERER_WINDOW_ERROR;
}
glfwMakeContextCurrent(m_main_window);
if (gl3wInit()) {
fprintf(stdout, "[EE] failed to initialize OpenGL\n");
return GLFW_CONTEXT_ERROR;
return RENDERER_CONTEXT_ERROR;
}
glViewport(0, 0, width, height);
printf("[DD] OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
glfwSetFramebufferSizeCallback(m_mainWindow, handle_resize_event);
glfwSetFramebufferSizeCallback(m_main_window, handle_resize_event);
return GLFW_OK;
return RENDERER_OK;
}
void render_manager::update(){
glfwSwapBuffers(m_mainWindow);
glfwSwapBuffers(m_main_window);
glfwPollEvents();
}
void render_manager::request_exit()
{
if (m_windowCloseCallback)
m_windowCloseCallback();
glfwSetWindowShouldClose(m_mainWindow, true);
if (m_window_close_callback)
m_window_close_callback();
glfwSetWindowShouldClose(m_main_window, true);
}