Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: How can i put a glut32-callback in a class?

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2002
    Location
    Germany
    Posts
    4

    How can i put a glut32-callback in a class?

    Hello,

    i try to put the callback funktion in a class, this function uses the class. The class ist binding the function to glut to.

    Have anybody an example of this situation?

    Regards,
    igel74

    example:

    ...
    //Bind "handle_resize" to glut
    void inithandler()
    {
    glutReshapeFunc(handle_resize); //won´t work
    }
    ...
    //resize
    GLvoid handle_resize(GLint width, GLint height)
    {
    if (height == 0) height=1;
    if (width == 0) width=1;
    transform(); //another class member
    }

  2. #2
    Junior Member Regular Contributor
    Join Date
    Feb 2002
    Posts
    133

    Re: How can i put a glut32-callback in a class?

    Originally posted by igel74:
    Hello,

    i try to put the callback funktion in a class, this function uses the class. The class ist binding the function to glut to.

    Have anybody an example of this situation?

    Regards,
    igel74

    example:

    ...
    //Bind "handle_resize" to glut
    void inithandler()
    {
    glutReshapeFunc(handle_resize); //won´t work
    }
    ...
    //resize
    GLvoid handle_resize(GLint width, GLint height)
    {
    if (height == 0) height=1;
    if (width == 0) width=1;
    transform(); //another class member
    }
    Check out "AtlAux" on google. There's a class
    in it that allows you to send functional callbacks to a class method.

    Regards,
    Jim
    -- http://www.mathies.com/glfaq/

    [This message has been edited by jmathies (edited 11-18-2002).]
    --
    Jim Mathies http://www.mathies.com/

    \"The best way to predict the future is to invent it."

  3. #3
    Junior Member Regular Contributor
    Join Date
    Oct 2002
    Location
    San Diego, CA, USA
    Posts
    211

    Re: How can i put a glut32-callback in a class?

    Your handle_resize(int, int) function is redefined by the compiler to be handle_resize(YourClass&, int, int). The only way to get around that is to make your function static, but that removes you from using variables in the class which are not static as well. I don't know exactly what you are doing, but when I program such things, for a callback I usually just use a global (C type) function which calls my in-class (C++ type) function.

  4. #4
    Intern Contributor nigels's Avatar
    Join Date
    Apr 2000
    Location
    Texas, USA
    Posts
    85

    Re: How can i put a glut32-callback in a class?

    You may be interested in using or
    studying the GLT C++ library that
    adapts GLUT callbacks into C++
    virtual function calls:
    http://www.nigels.com/glt/
    ---
    Regal - as OpenGL ought to be

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •