Commit 9a6e8581 authored by Tim Übelhör's avatar Tim Übelhör

added GLFW error callback

parent 5e5328d3
Pipeline #206633 passed with stage
......@@ -15,15 +15,14 @@ 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(const GLContext &) = delete;
GLContext(bool visible, bool fullscreen, int width, int height, int version_major = 4, int version_minor = 3);
GLContext(const GLContext&) = delete;
~GLContext();
/*!
\return the underlying window.
*/
GLFWwindow *get_window();
GLFWwindow* get_window();
int get_width();
int get_height();
......@@ -60,12 +59,12 @@ public:
void set_monitor_resolution();
private:
GLFWwindow *window;
GLFWwindow* window;
int width, height;
/*!
Finds the monitor in which the window is located
*/
GLFWmonitor *find_current_monitor();
GLFWmonitor* find_current_monitor();
};
} // namespace scigl_render
\ No newline at end of file
} // namespace scigl_render
\ No newline at end of file
......@@ -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)
: width(width), height(height)
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);
}
......@@ -59,7 +62,7 @@ GLContext::~GLContext()
std::cout << "destroyed the contex\n";
}
GLFWwindow *GLContext::get_window()
GLFWwindow* GLContext::get_window()
{
return window;
}
......@@ -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);
}
......@@ -115,7 +116,7 @@ void GLContext::set_resolution(int width, int height)
void GLContext::set_monitor_resolution()
{
GLFWmonitor *monitor;
GLFWmonitor* monitor;
if (is_fullscreen())
{
monitor = glfwGetWindowMonitor(window);
......@@ -140,23 +141,23 @@ void GLContext::toggle_fullscreen()
}
}
GLFWmonitor *GLContext::find_current_monitor()
GLFWmonitor* GLContext::find_current_monitor()
{
// window properties
int window_x, window_y;
glfwGetWindowPos(window, &window_x, &window_y);
int window_width, window_height;
glfwGetWindowSize(window, &window_width, &window_height);
GLFWmonitor **monitors;
GLFWmonitor** monitors;
// the winner
int largest_area = 0;
GLFWmonitor *best_monitor = NULL;
GLFWmonitor* best_monitor = NULL;
int n_monitors;
monitors = glfwGetMonitors(&n_monitors);
for (int i = 0; i < n_monitors; i++)
{
// monitor properties
const GLFWvidmode *mode;
const GLFWvidmode* mode;
mode = glfwGetVideoMode(monitors[i]);
int monitor_x, monitor_y;
glfwGetMonitorPos(monitors[i], &monitor_x, &monitor_y);
......@@ -177,4 +178,4 @@ GLFWmonitor *GLContext::find_current_monitor()
return best_monitor;
}
} // namespace scigl_render
\ No newline at end of file
} // namespace scigl_render
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment