S
slack_justyb
Well, I'll try to keep this short and sweet.
I'm trying to use glut which is a toolkit for OpenGL. Inside this
toolkit are a couple of functions that are giving me a slight problem
with trying to add to a class.
Here is the header for the class I would like to make (simplified and
error checking removed):
namespace myGlut {
class glutWindow {
public:
glutWindow();
glutWindow(std::string name, int x, int y, int w, int h);
void create();
void redraw(int _w, int _h);
void display();
void keyboard(unsigned char _k, int _x, int _y);
void loop();
private:
std::string title;
int xpos, ypos, width, height;
};
}
Now the details aside the method I'm really looking at here is the
create() method.
Inside this method is a call to a function inside the glut toolkit.
Here is the prototype for that function:
void glutDisplayFunc( void(*func)() );
Which as I see it, takes an address to a function (function pointer and
all that rot.)
However, the problem is that I would like to pass
myGlut::glutWindow::display() as the callback function.
therefore in my code I make a call like so:
void glutWindow::create() {
//Some really boring init stuff.
:
:
//Create a window with data members: title, xpos, ypos, width,
height.
:
:
glutDisplayFunc(myGlut::glutWindow::display);
:
:
//End of method
}
However, a conversion from void(*)() to void(myGlut::glutWindow::*)()
is not possible. Making things static, I believe but correct me if I'm
wrong, would solve the conversion but would really defeat the purpose
of making a class in the first place.
Finally, I just wanted to let everyone know that I am aware of C++
toolkits that wrap OpenGL, but I believe that what I'm asking is more
along the lines of a much broader question of how does one pass a
member function to some of the older C style functions that are looking
for a format of type(*)(...), eh?
Thanks for all the help!
Cheers and stuff from justyb's desktop!
I'm trying to use glut which is a toolkit for OpenGL. Inside this
toolkit are a couple of functions that are giving me a slight problem
with trying to add to a class.
Here is the header for the class I would like to make (simplified and
error checking removed):
namespace myGlut {
class glutWindow {
public:
glutWindow();
glutWindow(std::string name, int x, int y, int w, int h);
void create();
void redraw(int _w, int _h);
void display();
void keyboard(unsigned char _k, int _x, int _y);
void loop();
private:
std::string title;
int xpos, ypos, width, height;
};
}
Now the details aside the method I'm really looking at here is the
create() method.
Inside this method is a call to a function inside the glut toolkit.
Here is the prototype for that function:
void glutDisplayFunc( void(*func)() );
Which as I see it, takes an address to a function (function pointer and
all that rot.)
However, the problem is that I would like to pass
myGlut::glutWindow::display() as the callback function.
therefore in my code I make a call like so:
void glutWindow::create() {
//Some really boring init stuff.
:
:
//Create a window with data members: title, xpos, ypos, width,
height.
:
:
glutDisplayFunc(myGlut::glutWindow::display);
:
:
//End of method
}
However, a conversion from void(*)() to void(myGlut::glutWindow::*)()
is not possible. Making things static, I believe but correct me if I'm
wrong, would solve the conversion but would really defeat the purpose
of making a class in the first place.
Finally, I just wanted to let everyone know that I am aware of C++
toolkits that wrap OpenGL, but I believe that what I'm asking is more
along the lines of a much broader question of how does one pass a
member function to some of the older C style functions that are looking
for a format of type(*)(...), eh?
Thanks for all the help!
Cheers and stuff from justyb's desktop!