toggling an object

Hi, just wondering how to toggling an object with OpenGL, for example, if I press a key event, the certain object will not be displayed on the screen and if I press the same key event again, it will be shown.thanks in advance

Just do something like this:

int drawobjectflag=1;

void OnKeyPress()
{

drawobjectflag=-drawobjectflag;

}

void DrawScene()
{

if (drawobjectflag) DrawObject();

}

I have done what you suggested, but somehow the object still gets drawn if even the flag is turned to false.

void set_hand_pos(void)
{
  glLoadIdentity();
  draw_minute();
  glLoadIdentity();
  draw_hour();
  glLoadIdentity();
  if(flag)
  {
    draw_sec();
   }
}

Could be two problems one is your logic is not being set false = 0;
or that you are not clearing the screen for each update of the clock hands.

I have a clock demo on my website, www.angelfire.com/linux/nexusone/

Check it out to give you an idea of building a object.

Also would not use loadidentity, but glPush/Pop Matrix.

glPushMatrix();
draw_second_hand();
glPopMatrix();
glPushMatrix();
draw_hour_hand();
glPopMatrix();
etc…

Originally posted by godhand:
[b]I have done what you suggested, but somehow the object still gets drawn if even the flag is turned to false.

void set_hand_pos(void)
{
  glLoadIdentity();
  draw_minute();
  glLoadIdentity();
  draw_hour();
  glLoadIdentity();
  if(flag)
  {
    draw_sec();
   }
}

[/b]