I've created a C++ class (myPixmap
) to encapsulate the work performed by the OpenGL GLUT toolkit. The display()
member function of the class contains most of the code required to set up GLUT.
void myPixmap::display()
{
// open an OpenGL window if it hasn't already been opened
if (!openedWindow)
{
// command-line arguments to appease glut
char *argv[] = {"myPixmap"};
int argc = 1;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(30, 30);
glutCreateWindow("Experiment");
glutDisplayFunc(draw);
glClearColor(0.9f, 0.9f, 0.9f, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glutMainLoop();
openedWindow = true;
}
}
The display function passed to glutDisplayFunc()
is another member function of the class:
void myPixmap::draw(void)
{
glDrawPixels( m,n,GL_RGB,GL_UNSIGNED_BYTE, pixel );
}
However, gcc 4.2.1 on Mac OS X 10.6.4 refuses to compile this code, claiming that:
argument of type 'void (myPixmap::)()' does not match 'void (*)()'
Is there a way to use the GLUT toolkit inside a member function of a class, or must I call all GLUT functions within the main
function of the program?