Sign in to follow this  
tirengarfio

Trying to pass a variable to "display" function

Recommended Posts

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?

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

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

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this