Using menus to create objects but they aren't created immediately

I’m using the pop-up menus in OpenGL to allow users to input what item or picture they wish to create. When I activate the menu and click to, for example, “Create Agent”, it flashes the picture on the screen but then nothing is actually drawn. So when I activate the menu again for a 2nd time repeating the same thing it draws it. I am not sure what I am doing wrong. Here’s my sample code below:
void mainMenu(int value){
if(value == 1){ createAgent(); }
if(value == 0){ exit(0); }
}
void createDiamond()
{
glPushMatrix();
GLUquadricObj* mySphere2;
mySphere2 = gluNewQuadric();
gluQuadricDrawStyle(mySphere2, GLU_LINE);
glColor3f(0.0, 1.0, 1.0);
glLineWidth(2.0);

glTranslatef(0.0, -0.75, 0.0);
gluDisk(mySphere2, 0.2, 0.2, 3, 1);

glLoadIdentity();
glPopMatrix();

}

void createAgentTop(){
glPushMatrix();
GLUquadricObj* mySphere2;
mySphere2 = gluNewQuadric();
gluQuadricDrawStyle(mySphere2, GLU_LINE);
glColor3f(0.0, 1.0, 1.0);
glLineWidth(2.0);

glTranslatef(0.0, -0.5, 0.0);
gluDisk(mySphere2, 0.05, 0.05, 50, 1);

glLoadIdentity();
glPopMatrix();

}

void createAgent(){
glLoadIdentity();
createAgentTop();
createDiamond();
glFlush();
}

How are you storing your objects?

You know that you must redraw each object every screen refreash?

I use a reshape function whenever the screen is resized and/or moved…??? Could you explain what you mean further???

Originally posted by zsabrina:
I use a reshape function whenever the screen is resized and/or moved…??? Could you explain what you mean further???

What I think he means is that you must call createAgent() every time you need to have it drawn. With X every time you get an expose event you must redraw your scene and call createAgent(). Windows has something similar I’m sure. An alternative would be to have createAgent() create a display list, then your expose event could simply call the display list.

Let me try again. It does no good to call createAgent() in your menu code unless you are creating display lists. Try something like this:

int drawAgent=0;
void mainMenu(int value)
{
if(value == 1){ drawAgent = 1; }
if(value == 0){ exit(0); }
}
void expose() // this is your expose or refresh event
{
if(drawAgent) { createAgent(); }
}

Originally posted by zsabrina:
I use a reshape function whenever the screen is resized and/or moved…??? Could you explain what you mean further???

I have e-mailed you an example program.

But what I mean is that when you call your draw_screen agent, it must not only draw the new object, but also all past objects.

OpenGL once the scene has been rendered to the screen no longer has the object data of past objects.

SigSegV :
So basically I used your example of “expose” function as my display and embedded the if within my display function. This worked! Thanks!! Now let’s see if I can create other objects in this manner as well… without getting anymore bugs.
Thanks a bunch to everyone for helping!!!