Make graphics::window initialize gl3w upon context creation
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
|
||||
#include <utility> //exchange, swap, pair
|
||||
#include <cstring> //strlen, strncpy
|
||||
#include "config.hpp"
|
||||
|
||||
namespace graphics{
|
||||
static int initialize_global_glfw(){
|
||||
@@ -44,6 +45,8 @@ namespace graphics{
|
||||
if(initialize_global_glfw() != GLFW_TRUE)
|
||||
return; //TODO: user access to errors
|
||||
|
||||
GLFWwindow* current_context = glfwGetCurrentContext();
|
||||
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_FLOATING, GLFW_FALSE);
|
||||
@@ -55,6 +58,14 @@ namespace graphics{
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
m_window = glfwCreateWindow(width, height, title, nullptr, nullptr);
|
||||
make_current();
|
||||
if(gl3wInit() != GL3W_OK){
|
||||
debug_print_error("Unable to initialize OpenGL context!\n");
|
||||
destroy();
|
||||
}
|
||||
set_swap_interval(m_swap_interval);
|
||||
|
||||
glfwMakeContextCurrent(current_context);
|
||||
}
|
||||
window::window(const window& w):
|
||||
m_title(copy_title(w.m_title, strlen(w.m_title))),
|
||||
@@ -62,10 +73,11 @@ namespace graphics{
|
||||
m_refresh_rate(w.m_refresh_rate),
|
||||
m_swap_interval(w.m_swap_interval)
|
||||
{
|
||||
GLFWwindow* current_context = glfwGetCurrentContext();
|
||||
|
||||
copy_title(w.m_title, strlen(w.m_title));
|
||||
|
||||
GLFWwindow* current_context = glfwGetCurrentContext();
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, w.get_context_vmaj());
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, w.get_context_vmin());
|
||||
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
|
||||
@@ -80,6 +92,10 @@ namespace graphics{
|
||||
auto size = w.get_size();
|
||||
m_window = glfwCreateWindow(size.x(), size.y(), m_title, nullptr, nullptr);
|
||||
make_current();
|
||||
if(gl3wInit() != GL3W_OK){
|
||||
debug_print_error("Unable to initialize OpenGL context!\n");
|
||||
destroy();
|
||||
}
|
||||
set_swap_interval(w.m_swap_interval);
|
||||
set_pos(w.get_pos());
|
||||
set_visible(w.is_visible());
|
||||
|
||||
@@ -162,11 +162,11 @@ graphics::shader_program create_example_shader(){
|
||||
graphics::shader frag(fragment_source, graphics::shader::type::FRAGMENT);
|
||||
bool error = false;
|
||||
if(vert.has_compile_error()){
|
||||
debug_print("%s\n", vert.get_error().c_str());
|
||||
debug_print_error("%s\n", vert.get_error().c_str());
|
||||
error = true;
|
||||
}
|
||||
if(frag.has_compile_error()){
|
||||
debug_print("%s\n", frag.get_error().c_str());
|
||||
debug_print_error("%s\n", frag.get_error().c_str());
|
||||
error = true;
|
||||
}
|
||||
if(error)
|
||||
@@ -174,7 +174,7 @@ graphics::shader_program create_example_shader(){
|
||||
prog.attach_shaders(vert, frag);
|
||||
prog.link();
|
||||
if(prog.has_link_error()){
|
||||
debug_print("%s\n", prog.get_error().c_str());
|
||||
debug_print_error("%s\n", prog.get_error().c_str());
|
||||
}
|
||||
return prog;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ render_manager::render_manager(int width, int height, const char* title):
|
||||
m_main_window(width, height, title)
|
||||
{
|
||||
m_main_window.make_current();
|
||||
gl3wInit();
|
||||
glViewport(0, 0, width, height);
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glfwSetFramebufferSizeCallback(m_main_window, handle_resize_event);
|
||||
|
||||
Reference in New Issue
Block a user