Callback functions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • slack_justyb

    #1

    Callback functions

    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(unsign ed 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::glutWin dow::display() as the callback function.

    therefore in my code I make a call like so:

    void glutWindow::cre ate() {

    //Some really boring init stuff.
    :
    :
    //Create a window with data members: title, xpos, ypos, width,
    height.
    :
    :
    glutDisplayFunc (myGlut::glutWi ndow::display);
    :
    :
    //End of method
    }

    However, a conversion from void(*)() to void(myGlut::gl utWindow::*)()
    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!

  • Mike Wahler

    #2
    Re: [FAQ] Callback functions


    "slack_just yb" <justyb11@gmail .com> wrote in message
    news:1132565022 .634751.310730@ g49g2000cwa.goo glegroups.com.. .
    [color=blue]
    > However, a conversion from void(*)() to void(myGlut::gl utWindow::*)()
    > 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?[/color]

    This is addressed in the FAQ:



    -Mike


    Comment

    Working...