Original Post
For a school project, we're forced to use GLUT for our window initialization, mouse/keyboard capture, main loop, etc. I'm not really a fan of glut, as I'd prefer to roll my own functions, but that's beside the point. I've used glut often in the past, but just for small projects to test various things out. This, however, is a fairly large project. What I want to do is encapsulate my entire application in some CApp class, where I can store everything (window dimensions, title, meshes, etc), instead of having globals floating around. The problem is when I want the display/reshape functions to be part of the CApp class. Obviously, when I register these methods in main() with glutDisplayFunc(), it needs a static reference to the function. This means I have to declare my display function as static. This works, but now the problem is that I'm not allowed to call any non-static methods or variables within a static function. This turns into an ugly cycle where I'd be declaring everything as static. Another solution was to do something like this:
CApp g_app;
void display()
{
g_app.display();
}
int main()
{
...
glutDisplayFunc( display );
} Then CApp::display() wouldn't have to be static. This method works but seems a little hackish. /shrug. Does anyone have an idea on how to go about this in a cleaner way? If there are no other ideas I will settle for the 2nd method. ;) Thanks for reading. :)