GLUI function pointer problem

Started by
1 comment, last by Kishmet 15 years, 6 months ago
Hey - I hope this is the correct forum to post this on. GLUI is connected to OpenGl, so it seemed okay, but otherwise let me know. I'm developing a small game, and I've recently started adding a menu and HUD, but I keep running into a structuring problem. Let’s see if I can fraise this... The problem comes from the GLUI functions: glui = GLUI_Master.create_glui( "Menu", 0, 400, 50 ); GLUI_Rotation *rota = glui->add_rotation("Spin this", angles, 5, function); Where the "function" (last argument) has to be a pointer to a function. Now this works fine with all kinds of functions, as long as they are defined in a global scope, but I would like to structure my program, so the UI is a class. Changing the function to a member function: UI::function() gives compiler errors, so I guess what I'm looking for is some way to "wrap" the function into a pointer and then pass that. Have been looking at different materials, like: http://www.newty.de/fpt/callback.html But my problem is that I cant just change the function to accept a member function, since it is part of the GLUI library. And I refuse to believe that my UI has to be written in global scope =/ Anyone out there who have solved this problem? I think it is quite simple, I just haven’t found a solution for it. Thanks /kish
Advertisement
Problem is that the argument is a function pointer, but you're passing a member function pointer. The two are different things and are not compatible.

One solution would be to make the UI::function a static member function. A pointer to a static member function is compatible with a function pointer, but it is not at global scope, what you wanted to avoid.

Another solution is to store the instance of the class you want callback to be called on in some user storage within the GLUI components. For example, if you have an object foo that you want to call the member function function on on a callback, pass a pointer to foo to the custom data of the UI element, or whatever method for user data is provided, make a static function to extract the user data and call the member function and use if as the callback parameter. This static function is just a small function to route the message from a global callback to your member function call.
Thanks a lot, that was just the solution I was looking for.
Making the function static removed all the problems.


/kish

This topic is closed to new replies.

Advertisement