Reshape problem

Started by
0 comments, last by Gage64 15 years, 5 months ago
Hello, I am newbies to this website and also openGL. I just start to learn openGL recently and I have some reshaping question. So in my main function, I have so right button menu f_menu = glutCreateMenu(fileMenu); glutAddMenuEntry("box",1); And in my fileMenu function, when the choice equals to 1, (which is Menu1), I make it go to another function. void fileMenu(int id) { if (id == 1) drawBox(); } void drawBox() { glColor3f(0.0,0.0,0.0); glutSolidCube(1); glFlush(); } in which drawBox() draws box. It seems like it works but the problem is that the box shows up only like a sec (like flashing) then show me the stuff display() So what I mean is that whenever I try to draw box when user chooses box menu (in right clicked menu), it shows only for a sec (flashing) and then just return display and I am not sure why. Could you help me? Thank you.
Advertisement
The problem is that drawBox() only gets called when you select the box menu, so the box only gets drawn at that instant. If you want the box to be drawn from that point on, you have to call drawBox() each frame. A simple way to achieve this is to set a bool inside fileMenu(), and check that bool in display():

bool shouldDrawBox = false;void fileMenu(int id){    if (id == 1)        shouldDrawBox = true;}void display(){    if (shouldDrawBox)        drawBox();}


If you want to toggle the box drawing on and off when the box menu is selected, you'll need to switch the value of shouldDrawBox each time fileMenu() is called, like so:

void fileMenu(int id){    if (id == 1)        shouldDrawBox = !shouldDrawBox;}

This topic is closed to new replies.

Advertisement