Jump to content
  • Advertisement
Sign in to follow this  
Kishmet

OpenGL GLUI function pointer problem

This topic is 3689 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Thanks a lot, that was just the solution I was looking for.
Making the function static removed all the problems.


/kish

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!