I have created a virtual class with a basic draw() method which doesn't do anything. The purpose of this is that other classes, shapes and other stuff, which will be able to draw themselves in OpenGL, will inherit this virtual class, allowing me to create an array of pointers to many different classes. The idea behind this was that I was hoping I would be able to pass a pointer to this array into my glutDisplayFunc callback. (This happens to be named drawScene(). Unfortunately I don't seem to be able to pass anything to it, as glutDisplayFunc is designed to take a method which takes no parameters and return nothing.
Is there any way of passing arguments to callback functions, and then any way of passing a pointer into my drawScene function?
(TLDR? See below.)
Essentially I want to be able to do this:
class a{ ... };
void drawScene( a** a_array_pointer){ ... }
glutDisplayFunc(drawScene); // <-- How do I pass an argument into this?
Is there any way of passing arguments to callback functions, and then any way of passing a pointer into my drawScene function?
No. glut is really a C library, and the glutDisplayFunc
expects a function pointer as it's parameter. The only way to use variables in that callback, is to make them global or static variables of a class.