how to redraw the window with different data

I am trying to do following. I have structure myStruct that holds data for image.By calling


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.

yeah but how to call it…
I cant call it like this glutDisplayFunc(myFunction(myAnotherStruct))??

how would i do that?would you be kind to explain please

As aqnuep said. You can do it like this.

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

typedef struct YourStruct {
   //put something useful here
   Image img;
YourStruct o1, o2;

Create a global pointer name it it pCurrentObject.

YourStruct *pCurrentObject;

At init, assign pCurrentObject the reference of the object u want to show first.

void init() {
   pCurrentObject= &o1;

and in your display func. use the pCurrentObject

void display() {
   //setup modelview matrix
   //assume drawing the image

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;

Just to give u the idea.
Hope this helps,

This is the function that is always called when window needs to be redrawn…


In this function there is no way to pass parametric(current object)…

How do you let know function that does redraw which is


that needs to redraw with different “current object”?

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.

This isn’t complicated.

Hi.When i write this assignment…

pCurrentObject= &o1;

I get error saying " request for member in something not structure or union…

My struct looks something like this…

typedef struct YourStruct {
   //put something useful here
   Image *img;
YourStruct o1, o2;

I fixed it. It works now. Thank you