our_dick/src/render.cpp
2020-08-15 16:23:54 -07:00

61 lines
1.5 KiB
C++

#include <gl3w/GL/gl3w.h> // Must be included first
#include "render.hpp"
#include <stdio.h>
namespace
{
void handle_resize_event(GLFWwindow*, int width, int height){
printf("Window resized\n");
glViewport(0, 0, width, height);
}
}
render_manager::render_manager() :
m_window_close_callback (nullptr),
m_input_handler (nullptr),
m_main_window (nullptr){}
render_manager::RENDERER_ERROR render_manager::init (int width, int height, const char* title){
if (!glfwInit()) {
fprintf(stderr, "[EE] failed to initialize GLFW.\n");
return RENDERER_INIT_ERROR;
}
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 (stderr, "[EE] Could not create window\n");
return RENDERER_WINDOW_ERROR;
}
glfwMakeContextCurrent(m_main_window);
if (gl3wInit()) {
fprintf(stderr, "[EE] failed to initialize OpenGL\n");
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_main_window, handle_resize_event);
return RENDERER_OK;
}
void render_manager::update(){
glfwSwapBuffers(m_main_window);
glfwPollEvents();
}
void render_manager::request_exit()
{
if (m_window_close_callback)
m_window_close_callback();
glfwSetWindowShouldClose(m_main_window, true);
}