I have a class with instance functions (or methods?). From the instance I am trying to pass pointers to these functions to the library. The library expects static functions.
When I pass my pointers to callback functions, the compiler complains that my functions are not static. I tried to make them static, but if I do, then I canβt access the instance fields inside the functions.
How can I get around this?
A similar question: Using a member function of a C ++ class as a C callback function , where they suggest setting a method. However, I cannot do this, or I do not understand how I could.
The code
GlutController::GlutController (int argc, char **argv) {
glutSpecialFunc( OnSpecialKeys );
glutReshapeFunc( OnChangeSize );
glutDisplayFunc( OnRenderScene );
}
GlutController::~GlutController() {
}
void GlutController::OnChangeSize(int aNewWidth, int aNewHeight){
glViewport(0,0,aNewWidth, aNewHeight);
mViewFrustrum.SetPerspective( APP_CAMERA_FOV,
float( aNewWidth ) / float( aNewHeight ),
APP_CAMERA_NEAR,
APP_CAMERA_FAR );
mProjectionMatrixStack.LoadMatrix(
mViewFrustrum.GetProjectionMatrix() );
mTransformPipeline.SetMatrixStacks(mModelViewMatrixStack,
mProjectionMatrixStack);
}
void GlutController::OnRenderScene(void){
mGeometryContainer.draw();
}
void GlutController::OnSpecialKeys(int key, int x, int y){
mGeometryContainer.updateKeys(key);
}
: ++. ++, , . Java.