Trying to pass a variable to "display" function

Started by
2 comments, last by GameDev.net 17 years, 5 months ago
Hi, in my main function i have written this: glutDisplayFunc(display); and as you can imagine, i have above this function: void display (void); What im trying now is to pass a variable to the display func modifying in this way: glutDisplayFunc(display(&x)); void display(int *X); but it gives the next error: 'glutDisplayFunc': cannot convert parameter 1 from 'void(int *)' to 'void(__cdecl *)(void)' is there anyway to pass a variable to the function display?
Advertisement
I think not. Any function witch is passed in glut's displayFunc is considered a callback, and thus is defined in glut as no parameters. But what you could do, is define a class that handles rendering and define class struct that has parameters, and in run-time rendering change the parameters of the struct that display function uses.
Also note that any callback function defined in any class must be declared as static, or otherwise you'll get a lots of errors.
Quote:glutDisplayFunc(display(&x));

So x is global?
void display()
{
//global x lets use it;
int temp x1= x;
...
}


Is x in main scope?
templatevoid display(void)
{
//use T
int temp x1= *T;
...
}

int main.....
{
int the_x;
//register callbacks;
glutDisplayFunc(&display);
...
}

sorry if this is a double post the board borked.
Is x in main scope?template<int* T>void display(void){//use Tint temp x1= *T;...}int main.....{int the_x;//register callbacks;glutDisplayFunc( &display<&the_x> );...}

This topic is closed to new replies.

Advertisement