+2  A: 

The problem is that a pointer to an instance bound member function has to include the this pointer. OpenGL is a C API, and knows nothing about this pointers. You'll have to use a static member function (which doesn't require an instance, and thus no this), and set some static data members (to access the instance) in order to use glutDisplayFunc.

class myPixmap
{
private:
  static myPixmap* currentInstance;

  static void drawCallback()
  {
    currentInstance->draw();
  }

  void setupDrawCallback()
  {
    currentInstance = this;
    ::glutDisplayFunc(myPixmap::drawCallback);
  }
};

You may also have problems with C linkage vs C++ linkage, in which case you'll have to play around with extern "C". If so, you might have to use a global function, rather than a static member function as your callback, and have that call myPixmap::draw. Something like:

class myPixmap
{
public:
  void draw();

private:
  void setupDrawCallback();
};

myPixmap* g_CurrentInstance;

extern "C"
void drawCallback()
{
  g_CurrentInstance->draw();
}

void myPixmap::setupDrawCallback();
{
  ::g_CurrentInstance = this;
  ::glutDisplayFunc(::drawCallback);
}

With all of this, try to make as few changes as possible, since this is really kind of a kludge to deal w/ OpenGL being a C API.

If you want multiple instances (I don't think most people using GLUT make multiple instances, but maybe you are), you'll have to figure out a solution using a std::map to retrieve the instance:

static std::map<int, myPixmap> instanceMap;

Where you'd get the int to resolve which instance, I am not sure :)

FYI, you should define functions that take no parameters this way:

void some_function() { }

not

void some_function(void) { }
Merlyn Morgan-Graham
Thanks Merlyn; this is an excellent solution. I found that in my case, I had problems with C linkage vs C++ linkage, so I had to use a global function as shown in your second block of example code. Finally I was able to compile the program. I don't require multiple instances, so this is not an issue for me yet.
Nicholas Kinar