Game Development Reference
In-Depth Information
gramming perspective, or we have to find a way to give it a local reference by
passing it as a parameter. However, we just determined that the arguments have
already been decided by FreeGLUT and we cannot change them.
The workaround for this is to store our application in a global static pointer during
initialization.
static BulletOpenGLApplication* g_pApp;
With this pointer our callback functions can reach an instance of our application ob-
ject to work with at any time. Meanwhile an example declaration of one of our call-
backs is written as follows:
static void KeyboardCallback(unsigned char key,
int x, int y);
The only purpose of each of these callback functions is to call the equivalent function
in our application class through the global static pointer, as follows:
static void KeyboardCallback(unsigned char key,
int x, int y) {
g_pApp->Keyboard(key, x, y);
}
Next, we need to hook these functions into FreeGLUT. This can be accomplished
using the following code:
glutKeyboardFunc(KeyboardCallback);
The previous command tells FreeGLUT to map our KeyboardCallback() function
to any key-down events. The following section lists FreeGLUT functions which ac-
complish a similar task for other types of events.
Search WWH ::




Custom Search