MFSM || GlutIO module
Alexandre R.J. François
Module version: 0.3
FSF code version: 0.8
ARJF © 2007
contents
Description
Reference guide
Index
The GlutIO module encapsulates the GL Utility Toolkit (GLUT) for OpenGL
rendering, keyboard, mouse and joystick input (joystick not supported on all
platforms by GLUT API implementations).
The module is in theory cross-platform. A compilation variable
corresponding to the target platform must be set at compilation time.
Possible values are GLUTIO_CARBONGLUTIO_X11 (linux/X11), and GLUTIO_WIN32 (win32).
So far however, the module has only been successfully tested on Mac OS X and
on win32 platforms. The X11 version is currently not functional; the source
of the problem remains under investigation...
The module implements two main classes of functionalities present in the
GLUT API: creation and management of a GLUT-controlled OpenGL rendering
context, and handling and processing of interaction events generated by
control devices.
GLUT encapsulation
The CGlutIO class encapsulates the setup and operation of a single
GLUT-managed OpenGL rendering context. Most of the challenges (and
limitations of the resulting module elements) result from the sharing of the
context among multiple threads.
Control devices
the GLUT API defines mechanisms to handle and process events produced by input
devices: keyboard, mouse and joystick (the joystick API is not implemented for
all platforms. The GlutIO module encpasulates these functionalities and
integrates them in the SAI framework. The module defines event nodes for each
input modality, and input cells that generate the corresponding objects on an
active stream in response to a trigger by the appropriate GLUT callback.
GlutIO module elements are defined in the glutio namespace. This
section lists all the elements defined in the Image module, in alphabetical
order.
Encapsulate GLUT API for events and rendering context management.
Implements the singleton pattern: only one instance can exist at any time.
Data members
- static fsf::CMutex m_csContext : mutex for rendering context
- static int m_nWidth : context window width; updated automatically by
the window reshape callback; useful for manipulating window coordinates
associated with events
- static int m_nHeight : context window height; updated automatically by
the window reshape callback; useful for manipulating window coordinates
associated with events
- static CKeyboardInput *m_pKb : pointer to keyboard input cell
- static CMouseInput *m_pMs : pointer to mouse input cell
Mac OS X
- static CGLContextObj m_context : rendering context
X11
- static Display* m_display : display associated to context
- static GLXDrawable m_drawable : drawable associated with context
- static GLXContext m_context : rendering context
Win32
- static HDC m_hdc;
- static HGLRC m_context : rendering context handle
Member functions
Singleton instance management
- static CGlutIO* GetInstance() : singleton allocator, returns pointer
to unique instance (allocate it if does not already exist)
- static void DeleteInstance() : clean up
- static void Init() : initialization (create context, etc.)
- ~CGlutIO() : destructor
Callbacks
- static void DisplayCb(void) : display callback
- static void IdleCb() : idle callback
- static void ReshapeCb(int width, int height) : window resizing callback; updates context window width and height variables.
- static void KeyCb(unsigned char key, int x, int y) : keyboard callback
- static void MouseCb(int button, int state, int x, int y) : mouse (click) callback
- static void MotionCb(int x, int y) : mouse motion (one or more button pressed) callback
- static void PassiveMotionCb(int x, int y) : mouse passive motion (no button pressed) callback
- static void JoystickCb(unsigned int buttonMask, int x, int y, int z) : joystick callback
- static void RegisterKeyboardInput(CKeyboardInput *pKb) : bind keyboard input cell
- static void RegisterMouseInput(CMouseInput *pMs, bool bClick=true, bool bMotion=false, bool bActiveMotion=false) : bind mouse input cell
- static void RegisterJoystickInput(CJoystickInput *pJs, int pollInterval) : bind joystick input cell
Context switching
- static void ObtainContext() : context can only be current in a single thread at a time
- static void ReleaseContext() : must be called in order to make context available for other threads
Data access
- static int Width() : return context window width
- static int Height() : return context window height
Main loop
- static void MainLoop() : calls the GLUT main loop function to start processing events
CKeyboardEvent (fsf::CNode) "GLUTIO_KEYBOARD_EVENT"
Keyboard event node. Data corresponds to GLUT API.
Data members
- unsigned char m_key : key pressed
- int m_modif : modifier (SHIFT, CTRL, ALT) key state at the time the input key was pressed
- int m_x : mouse x position when key was pressed
- int m_y : mouse y location when key was pressed
Member functions
Constructors, destructor and other functions that are part of any derived node class
- CKeyboardEvent() : default constructor
- CKeyboardEvent(CNode *pParent, fsf::Time tTime=0) : initialization constructor
- CKeyboardEvent(const std::string &strName, CNode *pParent=NULL, fsf::Time tTime=0) : initialization constructor
- CKeyboardEvent(unsigned int key, int modif, int x, int y, fsf::CNode *pParent=NULL, fsf::Time tTime=0) : initialization constructor
- CKeyboardEvent(const std::string &strName, unsigned int key, int modif, int x, int y, fsf::CNode *pParent=NULL, fsf::Time tTime=0) : initialization constructor
- CKeyboardEvent(const CKeyboardEvent&) : copy constructor
- CKeyboardEvent& operator=(const CKeyboardEvent&) : assignment operator
- virtual CNode* Clone() : virtual cloning member function (necessary for run-time polymorphism)
- virtual void GetTypeID(std::string &str) : factory mapping key
Data access
- unsigned char Key() const : return key pressed
- void SetKey(unsigned char key) : set key pressed value
- int Modifier() const : return modifier value
- void SetModifier(int modif) : set modifier value
- int X() const : return mouse x coordinate value associated with event
- void SetX(int x) : set mouse x coordinate value associated with event
- int Y() const : return mouse y coordinate value associated with event
- void SetY(int y) : set mouse y coordinate value associated with event
CKeyboardInput (fsf::CCell) "GLUTIO_KEYBOARD_INPUT"
| Active filter | [FSF_ACTIVE_PULSE "Root"] |
| Passive filter | [FSF_PASSIVE_PULSE "Root"] |
| Output | (x (GLUTIO_KEYBOARD_EVENT "Keyboard event")) |
Keyboard input cell: generate keyboard events on callback from the GLUT
main loop. The Process() member function is not used (and thus not
overloaded).
Member functions
Constructors, destructor and other functions that are part of any derived cell class
- CKeyboardInput() : default constructor
- virtual void GetTypeID(std::string &str) : factory mapping key; must be overloaded in any derived cell
Active stream processing
- void MakePulse(CKeyboardEvent *pNode) : function called by the callback to send keyboard event on the active stream.
CMouseEvent (fsf::CNode) "GLUTIO_MOUSE_EVENT"
Mouse event node. Data corresponds to GLUT API.
Data members
- int m_button : button concerned by the event (left, right, middle)
- int m_state : button state (up or down)
- int m_x : window-relative x coordinate of mouse pointer
- int m_y : window-relative x coordinate of mouse pointer
Member functions
Constructors, destructor and other functions that are part of any derived node class
- CMouseEvent() : default constructor
- CMouseEvent(CNode *pParent, fsf::Time tTime=0) : initialization constructor
- CMouseEvent(const std::string &strName, CNode *pParent=NULL, fsf::Time tTime=0) : initialization constructor
- CMouseEvent(int button, int state, int x, int y, fsf::CNode *pParent=NULL, fsf::Time tTime=0) : initialization constructor
- CMouseEvent(const std::string &strName, int button, int state, int x, int y, fsf::CNode *pParent=NULL, fsf::Time tTime=0) : initialization constructor
- CMouseEvent(const CMouseEvent&) : copy constructor
- CMouseEvent& operator=(const CMouseEvent&) : assignment operator
- virtual CNode* Clone() : virtual cloning member function (necessary for run-time polymorphism)
- virtual void GetTypeID(std::string &str) : factory mapping key
Data access
- int Button() const : return event button value
- void SetButton(int button) : set event button value
- int State() const : return event button state value
- void SetState(int state) : set event button state value
- int X() const : return mouse x coordinate value associated with event
- void SetX(int x) : set mouse x coordinate value associated with event
- int Y() const : return mouse y coordinate value associated with event
- void SetY(int y) : set mouse y coordinate value associated with event
CMouseInput (fsf::CCell) "GLUTIO_MOUSE_INPUT"
| Active filter | [FSF_ACTIVE_PULSE "Root"] |
| Passive filter | [FSF_PASSIVE_PULSE "Root"] |
| Output | (x (GLUTIO_MOUSE_EVENT "Keyboard event")) |
Mouse input cell: generate mouse events on callback from the GLUT
main loop. The Process() member function is not used (and thus not
overloaded).
Member functions
Constructors, destructor and other functions that are part of any derived cell class
- CMouseInput() : default constructor
- virtual void GetTypeID(std::string &str) : factory mapping key; must be overloaded in any derived cell
Active stream processing
- void MakePulse(CMouseEvent *pNode) : function called by the callback to send mouse event on the active stream.
Registers the factories for the nodes and cells defined in the module, with the unique system instance.
C
R