By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,503 Members | 1,608 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,503 IT Pros & Developers. It's quick & easy.

Callback functions

P: n/a
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!

Nov 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"slack_justyb" <ju******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
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?


This is addressed in the FAQ:
http://www.parashift.com/c++-faq-lit....html#faq-33.2
-Mike
Nov 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.