Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: loop problem

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2004
    Posts
    7

    loop problem

    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);
    }

  2. #2
    Junior Member Regular Contributor
    Join Date
    Mar 2002
    Location
    Melbourne, Australia
    Posts
    224

    Re: loop problem

    See NeHe's tuts: here
    Everything you need is there

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2004
    Location
    mexico
    Posts
    125

    Re: loop problem

    change it to:
    Code :
       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
    Code :
    while(ok) { 
    renderEverything(); 
    if(keys[VK_UP])
    ok=!ok;
    }
    to exit when you press the up key

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •