Skip to content
Snippets Groups Projects
Commit 9a6e8581 authored by Tim Übelhör's avatar Tim Übelhör
Browse files

added GLFW error callback

parent 5e5328d3
No related branches found
No related tags found
No related merge requests found
Pipeline #206633 passed
......@@ -15,8 +15,7 @@ The copy constructor is deleted, use a shard_ptr.
class GLContext
{
public:
GLContext(bool visible, bool fullscreen, int width, int height,
int version_major = 4, int version_minor = 3);
GLContext(bool visible, bool fullscreen, int width, int height, int version_major = 4, int version_minor = 3);
GLContext(const GLContext&) = delete;
~GLContext();
......
......@@ -4,12 +4,17 @@
#include <scigl_render/gl_context.hpp>
#include <stdexcept>
void glfw_error_callback(int error, const char* description)
{
std::cerr << "GLFW Error code " << error << " description: " << description << std::endl;
}
namespace scigl_render
{
GLContext::GLContext(bool visible, bool fullscreen, int width, int height,
int version_major, int version_minor)
GLContext::GLContext(bool visible, bool fullscreen, int width, int height, int version_major, int version_minor)
: width(width), height(height)
{
glfwSetErrorCallback(&glfw_error_callback);
glfwInit();
// compability requirements
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, version_major);
......@@ -23,8 +28,7 @@ GLContext::GLContext(bool visible, bool fullscreen, int width, int height,
}
if (fullscreen)
{
window = glfwCreateWindow(width, height, "My Title",
glfwGetPrimaryMonitor(), NULL);
window = glfwCreateWindow(width, height, "My Title", glfwGetPrimaryMonitor(), NULL);
}
else
{
......@@ -42,12 +46,11 @@ GLContext::GLContext(bool visible, bool fullscreen, int width, int height,
}
if (!gl3wIsSupported(version_major, version_minor))
{
throw std::runtime_error("OpenGL " + std::to_string(version_major) + "." +
std::to_string(version_minor) + " not supported");
throw std::runtime_error("OpenGL " + std::to_string(version_major) + "." + std::to_string(version_minor) +
" not supported");
}
std::cout << "OpenGL Version: " << glGetString(GL_VERSION)
<< " GLSL Version: " << glGetString(GL_SHADING_LANGUAGE_VERSION)
<< "\n";
<< " GLSL Version: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << "\n";
std::cout << "width " << width << " height " << height << "\n";
glViewport(0, 0, width, height);
}
......@@ -89,8 +92,7 @@ void GLContext::set_fullscreen(bool enabled)
auto mode = glfwGetVideoMode(monitor);
int x_pos, y_pos;
glfwGetMonitorPos(monitor, &x_pos, &y_pos);
glfwSetWindowMonitor(window, monitor, 0, 0, width, height,
mode->refreshRate);
glfwSetWindowMonitor(window, monitor, 0, 0, width, height, mode->refreshRate);
}
// switch to windowed
if (!enabled && is_fullscreen())
......@@ -98,8 +100,7 @@ void GLContext::set_fullscreen(bool enabled)
auto monitor = glfwGetWindowMonitor(window);
int x_pos, y_pos;
glfwGetMonitorPos(monitor, &x_pos, &y_pos);
glfwSetWindowMonitor(window, NULL, x_pos, y_pos, width, height,
GLFW_DONT_CARE);
glfwSetWindowMonitor(window, NULL, x_pos, y_pos, width, height, GLFW_DONT_CARE);
}
glfwSwapBuffers(window);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment