Callback to a non-static C++ Member Function

Hey,

I'm trying to make a callback to a non static C++ member function in a class I made. The callback function is not designed by me. Only solutions I saw online were to make the function and related variable static but that does not go well with OpenGL and it's other functions.

Are there any other options that I can try to make this callback work.
I don't get what is the problem? You don't have access to this member function?
Can be more specific?
Hi ,
Can you past the code what you have written and what error you are getting ?
class OpenGL
{
public:
OpenGL(){}
~OpenGL(){}

// View
public:
GLShaderManager shaderManager;
GLMatrixStack modelViewMatrix;
GLMatrixStack projectionMatrix;
GLFrustum viewFrustum;

void changeSize(int, int);
}

^ this is in main.h and in main.cpp I have this

void OpenGL::changeSize(int w, int h)
{
glViewport(0, 0, w, h);
viewFrustum.SetPerspective(35.0f, float(w)/float(h), 1.0f, 500.0f);
projectionMatrix.LoadMatrix(viewFrustum.GetProjectionMatrix());
modelViewMatrix.LoadIdentity();
}

when I make a call to changeSize it gives me and error about void*
What is the callback function? I presume you are talking about the GLUT library's glutReshapeFunc callback?

GLUT is a very old library, and it was not designed to work with C++. A general solution is probably overkill; it is probably simplest to just write something that directly accesses your object:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
OpenGL* myopengl;

void MyReshapeFunc( int width, int height )
  {
  myopengl->changeSize( width, height );
  }

int main(...)
  {
  ...
  myopengl = &whatever_your_OpenGL_object_is_called;
  glutReshapeFunc( &MyReshapeFunc );
  ...
  }

There are other options, such as GlutMaster.
http://www.stetten.com/george/glutmaster/glutmaster.html

Good luck!
Topic archived. No new replies allowed.