Hi,
I am trying to do following. I have structure myStruct that holds data for image.By calling
glutDisplayFunc(myFunction);
I put that image in the window.
This is myFunction…
void myFunction(){
/*Use myStruct and draw image to the screen*/
Now at this point image is on the screen.
What I am trying to do now is on the press of the button or menu I would like to execute some other function that will
use another globally accessible struct myAnotherStruct and redraw window with data inside myAnotherStruct.
I guess I cant call glutDisplayFunc(anotherFunction) so I was wondering if anyone can help me or point me into some direction on how to accomplish this.
What about simply using a global variable indicating which struct you have to draw. This way you can use the same display function to draw all your images.
Supposing u have some struct (called YourStuct). You having two global objects o1 and o2 of it. The struct has whatever content u want. As as example i add an Image object as the struct member
In the keyboard input you may do something like this lets say u want to draw object o1 when ‘1’ is pressed and o2 when ‘2’ is pressed. In that case, u would add the following two cases in the keyboard func.
void OnKey(unsigned char whichKey, int x, int y) {
switch(key) {
case '1': pCurrentObject=&o1; break;
case '2': pCurrentObject=&o2; break;
}
glutPostRedisplay();
}
How do you let know function that does redraw which is
He just showed you how. You have a global variable which is accessible by the drawing method. This tells you what to draw. The display function uses this object to decide what to draw.