Requirements: C++11 compatible compiler, GLFW3, Boost.Lockfree.Queue. License: Boost Software License 1.0;
- Error handling:
- by default throws on errors, but
- custom error handling is supported: define
GLFW_CXX_CUSTOM_ERROR_HANDLING
- this requires you to define the functions
report_logic_error(std::string)
andreport_runtime_error(std::string)
in theglfw
namespace before including the library wrapper.
- this requires you to define the functions
- Max number of events per window: define
GLFW_CXX_MAX_EVENTS
before including the library.
#include <glfw/glfw.hpp>
glfw::environment::static_data glfw::environment::data;
int main() {
glfw::environment env;
glfw::window::hint(glfw::window_attribute::opengl_profile,
GLFW_OPENGL_CORE_PROFILE);
glfw::window::hint(glfw::window_attribute::opengl_forward_compat, GL_TRUE);
glfw::window::hint(glfw::window_attribute::context_version_major, 4);
glfw::window::hint(glfw::window_attribute::context_version_minor, 1);
glfw::window window{{1024, 768}, "my window"};
while (window) {
glfw::event event;
while (window.poll(event)) {
fprintf(stdout, "event: %s", to_string(event.type).c_str());
switch (event.type) {
case glfw::event_type::window_closed: {
window.close();
break;
}
case glfw::event_type::key_pressed: {
if (event.key.key == glfw::key::ESCAPE) {
window.close();
break;
}
}
}
}
}
return 0;
}
- enums for the configuration
- clean up the static storage of environment a bit.
-
glfw::environment
: only one instance should be created (typically by the main thread at the beginning ofmain
. -
glfw::window
: owning window (movable, non-copyable, semi-regular). -
glfw::event
(semi-regular):event_type
+ a union of event data. -
glfw::modifier_keys
: -
glfw::monitor
(semi-regular): -
glfw::video_mode
(regular): -
glfw::gamma_ramp
(regular):
glfw::event_type
:glfw::key
:glfw::mouse_button
:glfw::window_attribute
:
When a window is created an event queue is added to the glfw::environment
for
event polling. This is what allows you to poll events directly from the window.