Skip to main content
gamedev.net
🔒 Locked

Reshape problem

Started by chj0216 Nov 24, 2008 at 12:16 AM 0 replies 400+ views
Original Post
chj0216
chj0216
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.
Gage64
Gage64
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;}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.