- Notifications
You must be signed in to change notification settings - Fork7
Simple event queue for GLFW 3
License
glfw/gleq
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
GLEQ is a basic, header-only event queue library for GLFW 3. It adds GLFWevents for monitors, joysticks and windows to a single global queue. Nothingmore.
GLEQ is inspired bySDL andGLWT, and is writtenas an example forpeople requesting that GLFW provide an event queue API, to show how easy it isto implement on top of GLFW callbacks.
GLEQ is written in C and depends only on GLFW 3.0 or later.
GLEQ is a work in progress and the interface may change but it works as intendedand covers nearly all events up to and including GLFW 3.3. Just drop it intoyour project and include it after the GLFW header.
GLEQ is licensed under thezlib/libpnglicense.
To use GLEQ, includegleq.h
after the GLFW header. To add the implementationof GLEQ, defineGLEQ_IMPLEMENTATION
before including the GLEQ header inexactly one source file.
#include<GLFW/glfw3.h>#defineGLEQ_IMPLEMENTATION#include"gleq.h"
If you will only be using GLEQ in a single source file, you can makeall itsfunctions static by definingGLEQ_STATIC
as well.
#include<GLFW/glfw3.h>#defineGLEQ_IMPLEMENTATION#defineGLEQ_STATIC#include"gleq.h"
After GLFW has been successfully initialized, callgleqInit
. This willreplace the monitor and joystick callbacks.
if (!glfwInit())return false;gleqInit();
Once a GLFW window is created, you can track it withgleqTrackWindow
. Thisreplaces all callbacks on that window.
gleqTrackWindow(window);
Event processing is done as usual withglfwPollEvents
,glfwWaitEvents
orglfwWaitEventsTimeout
. Events for monitors, joysticks and tracked windows areadded to the queue as GLFW reports them.
Event retrieval is done withgleqNextEvent
and each event is then freed withgleqFreeEvent
.
GLEQeventevent;while (gleqNextEvent(&event)){switch (event.type) {caseGLEQ_WINDOW_RESIZED:printf("Window resized to %ix%i\n",event.size.width,event.size.height);break; }gleqFreeEvent(&event);}
The call togleqFreeEvent
frees any memory allocated for the event and clearsthe event struct. Currently only the file drop event allocates memory, but it'srecommended to call it for every event once it has been processed.
No, only GLFW callbacks.
Only to save a deep copy of the path list provided to the file drop callback.The event queue itself is a global static array.
It depends. Also, the size of the queue can be controlled withGLEQ_CAPACITY
.
It depends. The native event queue wrapped by GLFW is global, too.
GLEQ is intended to be a simple example event queue. Having a queue per windowwould make it more complicated than it needs to be.
GLEQ is intended to be a simple example event queue. Making it thread safewould make it more complicated than it needs to be.