PDA

View Full Version : loop problem



mk
12-21-2004, 06:07 AM
Can somebody tell me why this programm snippet always uses the else-case and ignores the if-cases? What can I do to hold the program until the user decides to press a key?

if (keys[VK_LEFT])
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_FALSE);
}

if (keys[VK_RIGHT])
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
}

else
{
exit(0);
}

MickeyMouse
12-21-2004, 06:35 AM
See NeHe's tuts: here (http://nehe.gamedev.net/)
Everything you need is there:)

zukko
12-21-2004, 08:53 PM
change it to:

if (!keys[VK_RIGHT])
{
exit(0);
}

else
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);

} btw on your main function you should be doing something like


while(ok) {
renderEverything();
if(keys[VK_UP])
ok=!ok;
} to exit when you press the up key