View Full Version : toggling an object
godhand
04-14-2004, 05:29 AM
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();
...
}
godhand
04-15-2004, 05:06 AM
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();
}
}
nexusone
04-15-2004, 02:56 PM
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/ (http://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:
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();
}
}
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.