Im beginning in opengl, im using GLUT and I have problems with GLUT callbacks in C++ because GLUT was made for C and not for C++.
Â¿how can i do callbacks in C++ with GLUT?
I have found only one page about it, and i have not understood that at all.
Â¿Is a better choice to use another API like “GLOW” that is an adaptation of GLUT to C++?
thanks a lot.
Callbacks in C++ works just like in C. Pass a pointer to a function you want to be called on an event. There’s no difference between C and C++ in that sense.
What I think you actually want is to pass a member function. That, however, won’t work. Pointer to functions and pointer to member functions are different, and GLUT doens’t know about classes or member fuctions.
Whether some other API is better depends entirely on what YOU want, not what we want. You have to ask that question to yourself, not us. If you want to pass member functions and GLOW supports it, then obviosly it’s a better choise. But there are other factors that can be concidered as “better”, and that’s for you to decide.
Yes, I want to pass a member function of a class and GLUT can’t accept that.
You might try creating a singleton class, using static members for the GLUT callbacks, then use virtual functions on the singleton to fire the GLUT events that are raised. You could use this as a base class for your GLUT apps.
That’s the solution that I had found, but It seems a hard solution.
I think is a better choice to use GLOW API, the work is done and is easy to use.