#include <gl/freeglut.h>
void Keyboard(int value){
glutTimerFunc(33,Keyboard,0);
}
int main(int argc, char **argv){
glutTimerFunc(33,Keyboard);
}
Is there any way to pass data from the main function to the keyboard function without having to use global variables? It seems like the function glutTimerFunc only allows functions with the signature (int value) which seems very restrictive.
Like other people already suggested: Don’t use GLUT. GLUT never was meant to be the foundation of serious application. It’s a small framework meant for small OpenGL tech demos. The problem you’re running into is that C and C++ lack a concept called “closures”, or sometimes also called “delegates”. Other languages have them and in fact when you use the GLUT bindings in those languages you don’t experience the problem.
Since C/C++’s lack of closures is so prominent a small library (that does crazy but genius things internally) has been written, that allows it, to create closures in C. It’s called ffcall, unfortunately seems to be unmaintained, but is in use by projects as the GNU Common Lisp and Scheme compilers.
I wrote about using ffcall already in the StackOverflow answers https://stackoverflow.com/a/8375672/524368 and https://stackoverflow.com/a/10207698/524368