If anyone knows much about openGL/ glut i'd appreciate the help.
1 2 3 4 5 6 7 8 9 10
void handleKeypress(unsignedchar key, int x, int y)
{
if(key == 27) //27 is escape
{
exit(0);
}
}
//in main
glutHandleKeypress(handleKeypress);
Escape works and the program closes. But nothing else works. If i swap 27 for any other key. Eg VK_UP for the up key on windows. the program does not exit.
(windows.h is included)
Also if i swap what escape does.
Eg:
1 2 3 4
if(key == 27)
{
std::cout << " Keypress";
}
It doesnt output, the only thing i can get to work is escape to close the window. Am i doing soemthing wrong?
One thing I can say is that comparing it with VK_* doesn't make much sense because it's a different encoding. VK_KEY_A does correspond to ASCII value for 'A' (capital A), but the comparison wouldn't work for lowercase 'a', so be sure to use toupper/tolower if you want to detect the key press, and not a specific character.
The reason why it doesn't output anything if you change exit(0) to std::cout << may hide in the fact that the buffer is not flushed. Try changing it to std::cout << " Keypress" << std::endl; or call std::cout.flush(); manually.