Game Development Reference
In-Depth Information
Here is a code snippet of the basic class declaration for BulletOpenGLApplica-
tion :
class BulletOpenGLApplication {
void Initialize();
virtual void Keyboard(unsigned char key, int
x, int y);
virtual void KeyboardUp(unsigned char key,
int x, int y);
virtual void Special(int key, int x, int y);
virtual void SpecialUp(int key, int x, int y);
virtual void Reshape(int w, int h);
virtual void Idle();
virtual void Mouse(int button, int state, int
x, int y);
virtual void PassiveMotion(int x, int y);
virtual void Motion(int x, int y);
virtual void Display();
These essential functions make up the important hooks of our application layer class.
The functions have been made virtual to enable us to extend or override them in fu-
ture projects.
As mentioned previously, FreeGLUT has different functions for different purposes,
such as when we press a key, or resize the application window. In order for
FreeGLUT to know which function to call at what moment, we make a series of calls
that map specific actions to a custom list of callback functions. Since these calls
will only accept function pointers that follow specific criteria in return value and input
parameters, we are restricted to using the arguments listed in the previous functions.
Meanwhile, by their nature, callback functions must call to a known, constant place
in memory; hence a static function fits the bill. But, static functions cannot perform
actions on nonstatic or nonlocal objects. So, we either have to turn the functions
in BulletOpenGLApplication static, which would be incredibly ugly from a pro-
Search WWH ::

Custom Search