Interaction between libraries from a GLUT callback


I have a graphics engine library, say GFX, and wants it to interact with a physics engine library, say PHYS.
I use glutMainLoop() in the main() application, which links to libGFX and libPHYS.
The GFX have a “Scene” singleton which I can use from the static GLUT callbacks.

Now I try to figure out how to share data between PHYS and GFX.
Is it a sensible approach to access two singletons in the GLUT callbacks, like:
Scene& s = Scene::Instance();
Phys& p = Phys::Instance();
and maybe let a third library, PHYSGFX, handle the interaction?

Maybe this question and description was a bit unclear (my eyes are crossing now), but to summarize I want something like:
There should be no dependencies between the two libraries PHYS and GFX, and I need to share data between the two from a static GLUT callback, since I’m using glutMainLoop().

Any ideas?
Maybe I can get a clue from how it’s done in {OSG, Ogre3D}x{Bullet, ODE} but any thoughts would be much appreciated.

Many people here would advise you not to use glut. It, at least, narrows your possibilities down (mainly for design).

I think the easiest way to do so, talking with design patterns, is to use Façade (

Thank you for your advice!

Facade might be good for both API:s, but first I have to find out the interactions (which should give me hints about how to design the facades in a refactoring process).
But, as I understand it, the Facade is just a way of cleaning up the interface and does not change where the object instances live or who they interact with, more than with possible indirections.

Hmm, no GLUT you say. Are there any popular solutions or do you use GLX directly?

[begin of parenthesis]
Well, I must admit I try to avoid using too much design patterns. They are good, but using them too much make the code very complicated to understand since they add a lot of indirections. I like to take inspiration from them to make my code more organized, more easy to understand, but not use them to say ‘hey I use many design patterns !’. So it’s now up to you if you want to make a real full implementation of façade, or to understand them and make a code with no/less dependencies thanks to the understandings.
[end of parenthesis]

I personally use glx/wgl directly. But you can also use SDL, SFML or any others. You can even stay with glut as long as you feel it’s enough for what you’re doing.

If you’re not familiar with wgl/glx and want to get rid of glut, then I would advise to start with SDL or SFML (I found SFML more easy to use but it might have some bugs with GL > 3.0) and move later (if really needed or wanted) to wgl/glx.

Hope that helps.

Thanks! I agree with your view on design patterns and try to do the same, but I’m sadly not much of an expert on them.

Yes I’ll stay with freeglut for now (no time to change), but will for sure investigate the alternatives you suggested later on.

I will try my approach with two libraries and a “governing” one responsible for data transmission between the two worlds (physics and graphics) as well as handling common objects.