GLUT callback registration (not quite OT)

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

    GLUT callback registration (not quite OT)


    Hi all. I'm having trouble registering a GLUT callback function.
    glutIdleFunc wants a void(*)() function as argument, and I believe
    that's what I've given it, but gcc complains with the following message:

    GraphicDisplay. cpp:15: error: no matches converting function `DrawC' to
    type `void (*)()'
    GraphicDisplay. hpp:11: error: candidates are: void GraphicDisplay: :DrawC()

    Can anyone see what I'm missing here?

    //---begin code:

    class GraphicDisplay
    {
    public:
    void Init();
    void DrawC();
    };

    void GraphicDisplay: :Init()
    {
    // Standard GLUT init stuff...
    // (snip)
    glutIdleFunc( GraphicDisplay: :DrawC );
    }

    void GraphicDisplay: :DrawC()
    {
    // some code...
    }

    //---end code.

  • Ivan Vecerina

    #2
    Re: GLUT callback registration (not quite OT)

    "Martin Magnusson" <loveslave@frus tratedhousewive s.zzn.com> wrote in message
    news:bjb2me$flc $1@green.tninet .se...[color=blue]
    > GraphicDisplay. cpp:15: error: no matches converting function `DrawC' to
    > type `void (*)()'
    > GraphicDisplay. hpp:11: error: candidates are: void GraphicDisplay: :DrawC()[/color]

    Glut is a C library, and it expects a pointer to a C function.
    So you cannot pass a non-static member function to it.

    What will probably work is to replace:[color=blue]
    > void DrawC();[/color]
    with:
    static void DrawC();

    But yes, this will force you to use global variables (DrawC will not
    be able to access non-static member variables of class GraphicDisplay.


    Note that, in theory, you also need to add an extern "C"
    in front of the function's declaration (this is to formally
    follow the standard, but this is rather rarly used in such
    a context...)



    hth,
    --
    http://www.post1.com/~ivec <> Ivan Vecerina


    Comment

    Working...