Key handling in opengl, where?
Where do you keep your keyhandling in an opengl windows program with KEYDOWN/UP calls?
In WinMain or in the gl-code? Anywhere else?
You can use WM_MESSAGE to handle keys; I prefer to check key directly so you can easily manage multiple keys
virtualkeycode= VK_UP, VK_LEFT, VK_CONTROL,...(see VK_ on your reference...)
bool IsKeyPressed(int virtualkeycode){ // check bit 15 return((GetKeyState(virtualkeycode)&(1<<15))!=0);}
virtualkeycode= VK_UP, VK_LEFT, VK_CONTROL,...(see VK_ on your reference...)
I have a separate class for that. The WndProc function receives the messages from Windows, of course, and stores the state changes in my input class. I have pointers to that input object where ever I might need to use it.
I use two methods. One is a simple message type, the other is just at the start of my rendering code.
bascially
onidle=renderingfunc
then the rendering func consists of bascially
getasynckeystate()
updatepositions(time)
renderdisplay()
I prefer getasynckeystate as opposed to the key messages, but either does the trick well (just depends on how you lay out the program)
bascially
onidle=renderingfunc
then the rendering func consists of bascially
getasynckeystate()
updatepositions(time)
renderdisplay()
I prefer getasynckeystate as opposed to the key messages, but either does the trick well (just depends on how you lay out the program)
If you want to use WM_MESSAGE you should keep track of your keyboard state by toggling a bit flag
Something like this
KEY_DOWN -> bPressed(key) = TRUE
KEY_UP -> bPressed(key) = FALSE
Something like this
KEY_DOWN -> bPressed(key) = TRUE
KEY_UP -> bPressed(key) = FALSE
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement