glut***func and member functions
I am trying to abstract away from the opengl initialization process. What I want to do is put all the startup stuff in a class like this. The problem is that the glutDisplayFunc is this:
argument of type `void (Engine::)()' does not match `void
(*)()'
class Engine{
void render(){ /.../ };
void setFuncs(){
glutDisplayFunc(render);
}
void go(){
glutMainLoop();
}
}
void Main()[
Engine engine;
engine.setFuncs();
engine.go();
}
The functions passed to glut cannot be class member-functions. They must either be free functions, or static class functions.
One possibility might be something like this:
Obviously this won't work properly if you have more than one Engine instance, and you're taking a (slight) performance hit.
- Neophyte
One possibility might be something like this:
// Engine.cpp fileEngine* pEngine = 0;void renderFunc() { if ( pEngine ) pEngine->render();}void Engine::setFuncs() { pEngine = this; glutDisplayFunc ( renderFunc );}
Obviously this won't work properly if you have more than one Engine instance, and you're taking a (slight) performance hit.
- Neophyte
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement