Solved

about  GLUT, 'glutKeyboardFunc'

Posted on 2004-09-26
2
6,300 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
ID: 12157190
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
ID: 12198349
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

785 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