Jump to content
  • Advertisement
Sign in to follow this  
chj0216

OpenGL Reshape problem

This topic is 3672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!