Solved

about  GLUT, 'glutKeyboardFunc'

Posted on 2004-09-26
2
6,062 Views
Last Modified: 2008-01-09
hello,

i having problem with my spacebar

i need to have the space key toggle the animation on and off.
however, i really can't find any relevant example about this topic.

this is wat i've found
==========================================================
   glutKeyboardFunc( processKeys );
   glutSpecialFunc( processSpecialKeys );


void processKeys(unsigned char key, int x, int y) {

      if (key == 27) // escape key
            exit(0);
}

void processSpecialKeys(int key, int x, int y)
{
      switch(key) {
            case GLUT_KEY_UP :
                  pos_y+=2;
                  break;
            case GLUT_KEY_DOWN:
                  pos_y-=2;
                  break;
            case GLUT_KEY_LEFT:
                  pos_x-=2;
                  break;
            case GLUT_KEY_RIGHT:
                  pos_x+=2;
                  break;
      }
}

==========================================================

can anyeone gimme any suggestion?
0
Comment
Question by:tom_mk
2 Comments
 
LVL 2

Accepted Solution

by:
bcsonka earned 500 total points
Comment Utility
Hi,

In the processKeys function check for (key == 32) to check to see if the spacebar is pressed.  Here's an example . . .

=============================================================================

void processKeys(unsigned char key, int x, int y)
{
     if(key == 27) // escape key
     {
          exit(0);
     }
     else if(key == 32) // spacebar key
     {
          // toggle animation
     }
}

=============================================================================

I hope that helps.
0
 
LVL 9

Expert Comment

by:zaghaghi
Comment Utility
the ASCII code of spacebar is 32.
so u can check o see if the `key' parameter is 32 in an `if' statement.
u can use Sleep function to puase the program

good luck
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now