Jump to content
  • Advertisement
Sign in to follow this  
Skelit

OpenGL How can I handle keyboard input with opengl?

This topic is 3581 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

I want to simply move something on the screen while a key is being held down, and stop moving while it is let go. I've done some googling but I can't seem to find anything about it. The best I've found was checking to see if a key was down, and that works, but I can't seem to find out how to check if the key was released.

Share this post


Link to post
Share on other sites
Advertisement
The G in OpenGL stands for "graphics". OpenGL doesn't handle input. You are probably using an auxiliary library of some sort, like SDL, SFML, GLUT or even your raw platform API. You need to give more information.

Share this post


Link to post
Share on other sites
Oh, ok. I just thought there would be another way since there is a glutKeyboardFunc function.

Whatever, I'll just use SDL since I'm familiar with that. Thanks!

Share this post


Link to post
Share on other sites
Quote:
Original post by Skelit
Oh, ok. I just thought there would be another way since there is a glutKeyboardFunc function.

Whatever, I'll just use SDL since I'm familiar with that. Thanks!


That function exists because GLUT is "The OpenGL Utility Toolkit", which adds additional utilities to OpenGL. However, GLUT is a bit dated and takes a C approach to setting up your program, so it is good for some simple things but more complicated things you might want to try another framework (such as GLFW)

Might I suggest giving SFML a try as well. Here is their OpenGL tutorial and here is their events tutorial if you want to see how the code is structured.

Overall I found that SFML is much more enjoyable to use due to it being a native C++ library rather than SDL, which is a C library. SDL is far more used due to it being very mature and being around awhile, but SFML is an up and coming library that seems to be gaining more and more exposure. I personally find using SFML very enjoyable and easy compared to SDL, but your millage my vary. I am currently using SFML as the main framework around a closed source game engine due to some of the extra features it adds and allows, it is working great so far. Good luck!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!