glut***func and member functions

Started by
1 comment, last by waxor 19 years, 6 months ago
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(); }
Advertisement
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:
// 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
I feel silly.

A little net research found me the solution. The function passed must be a static function. Making render a static fuction fixed it all good.


-Mikel

This topic is closed to new replies.

Advertisement