OpenGLEAN Device Support Development
Summary
|
CVS
|
(discussion via home page)
|
(contact via home page)
|
(suggestion box)
|
License
|
Todo
|
Bugs
This proposal was originally authored for OpenGLUT.
This proposal is limited to the scope of the OpenGLEAN input handling API including keyboard, mouse and joysticks. In the context of gleandev this API proposal should only apply to joysticks. See also Device API Proposal for other input device discussion.
There are several aspects of OpenGLEAN input handling that can be improved. GLUT evolved over time retaining backwards compatibility, introducing some degree of duplication and inconvenience. The GLUT abstraction of joysticks has been superceded by technical advances - USB, additional axes and analog (non-binary) buttons. Another limitation of the GLUT API is support for only one keyboard, one mouse and one joystick.
NB: Multiple keyboard support is the OS or window system responsibilty. For modern systems, depending on configuration, you either get all keyboards multiplexed to a single workstation console or you can in principle have them each available as part of a separate console. This is far and away outside of the purview of a library such as OpenGLEAN.
Support for multiple keyboards is provided by means of the current keyboard context which can be optionally queried or set by the application.
void glutKeyboardConnect (void (*func) (int state))
Parameters
- func an application specific keyboard connect event handler
- state is either GLUT_CONNECT or GLUT_DISCONNECT
void glutKeyboardKey (void (*func) (unsigned int key, int state))
Parameters
- func an application specific keyboard key event handler
- key the key that has been pressed or released, including special keys
- state GLUT_UP or GLUT_DOWN
Notes
- All connected keyboards use the same event handler
- The event relates to the current keyboard context
- The keycode is either the ASCII code, or a special key such as GLUT_KEY_F1
- The mouse position should be queried if needed, rather than passes with every event
This form of keyboard handling consolidates the two GLUT API calls: glutKeyboardFunc() and glutSpecialFunc().
NB: See the note about workstation keyboards. That applies equally well here. This subsection of the proposal should be struck, as it was written without considering extant OS technology..
Support for multiple mice is provided by means of the current mouse context which can be optionally queried or set by the application.
void glutMouseConnect (void (*func) (int state))
Parameters
- func an application specific mouse connect event handler
- state is either GLUT_CONNECT or GLUT_DISCONNECT
void glutMouseButton (
void (*func) (unsigned int button, int state, int x, int y)
)
Parameters
- func an application specific keyboard key event handler
- button the button that has been pressed or released
- state GLUT_UP or GLUT_DOWN
- x and y is the position of the mouse press or release
void glutMouseMotion (void (*func) (int state, int x, int y))
Parameters
- func an application specific keyboard key event handler
- state GLUT_DOWN if any button is being held, else GLUT_UP
- x and y is the position of the mouse
void glutJoystickConnect (void (*func) (int state))
Parameters
- func an application specific joystick connect event handler
- state is either GLUT_CONNECT or GLUT_DISCONNECT
void glutJoystickButton (void (*func) (unsigned int button, int state))
Parameters
- func an application specific keyboard key event handler
- button the button that has been pressed or released
- state GLUT_UP or GLUT_DOWN
Keypress, mouse button and joystick button state transitions are sent to OpenGLEAN windows as GLUT_UP or GLUT_DOWN events. It is also useful to know about keys or buttons currently being held down. Analog inputs such as joystick axes are more conveniently treated as continuously changing state, rather than individual events.
int glutGetKey (unsigned int param)
Parameters
- param is either an ASCII key code, or a special key such as GLUT_KEY_F1
Returns GLUT_DOWN for a key held down in the current keyboard context, GLUT_UP else.
int glutGetButton (unsigned int param)
Parameters
- param is a button numbered from 0.
Returns GLUT_DOWN for a mouse button held down in the current mouse context, GLUT_UP otherwise.
Parameters
- param is either GLUT_POSITION_X or GLUT_POSITION_Y
Returns the x or y position of the current mouse context.
GLdouble glutGetAxis (unsigned int param)
Parameters
- param is either GLUT_JOYSTICK_BUTTON_1, GLUT_JOYSTICK_BUTTON_2, ...
- param is either GLUT_AXIS_1, GLUT_AXIS_2, ...
For digital buttons, returns 1 for joystick buttons held down in the current joystick context, 0 otherwise.
For analog buttons, returns a number in the range [0,1] with 0 for unpressed, 1 held with down completely.
For analog axes, returns a number in the range [-1,1] with 0 being neutral.
For applications supporting multiple keyboards, mice or joysticks.
Get the current input context, in order to identify the individual device.
Set the current input context, for querying state of specific devices.
int glutGetKeyboard (void)
void glutSetKeyboard (int keyboard);
int glutGetMouse (void)
void glutSetMouse (int mouse);
int glutGetJoystick (void)
void glutSetJoystick (int joystick);
Supported in part by SourceForge.net.
Generated on Fri Sep 9 18:01:32 2005 for gleandev by
doxygen 1.4.3
The OpenGLEAN project is hosted in part by
SourceForge.