Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Tompa

OpenGL Key handling in opengl, where?

This topic is 5531 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Where do you keep your keyhandling in an opengl windows program with KEYDOWN/UP calls? In WinMain or in the gl-code? Anywhere else?

Share this post


Link to post
Share on other sites
Advertisement
You can use WM_MESSAGE to handle keys; I prefer to check key directly so you can easily manage multiple keys


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...)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!