Jump to content
  • Advertisement
Sign in to follow this  
MrDoomMaster

OpenGL DirectInput + OpenGL?

This topic is 4819 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 don't know about you guys, but using WM_KEYDOWN and WM_MOUSEMOVE to detect input in OpenGL is very slow and inefficient. Is it recommended to use DirectInput with OpenGL for keyboard and mouse input? What would you guys recommend for input in OpenGL? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
You could always use GetAsyncKetState, which you can call anytime in your program to detect if the key is up or down. You can use GetCursorPos to get the position of the mouse.

A good macro that I like to use when using GetAsyncKeyState is as follows:
#define KEYDOWN( vk_code ) ( ( GetAsyncKeyState( vk_code ) & 0x8000 ) ? 1 : 0 )
#define KEYUP( vk_code ) ( ( GetAsyncKeyState( vk_code ) & 0x8000 ) ? 0 : 1 )

Here are some examples:
// if the enter key is down
if( KEYDOWN( VK_RETURN ) )
{ // do whatever }

// if the 'a' key is up
if( KEYUP( 'a' ) )
{ // do whatever }

Of course, you can always use DirectInput, but if you want minimal hassle you can just use those.

Share this post


Link to post
Share on other sites
If you plan on using the Win32 API for OpenGL, then I'd highly suggest using DirectInput if you are making a game that input is main component of. If you are just making a small demo or a simple game, then I'd say use what ussnewjersey4 suggested.

However, if you use an OpenGL library, such as GLFW, GLUT, or SDL, then there are input systems built in that you can use. I'd personally use GLFW or SDL as my main source for handeling input with OpenGL, but if you don't have that luxery, then DI/Win32 API it is. More infomration on those libraries here.

Share this post


Link to post
Share on other sites
Quote:
Original post by MrDoomMaster
I don't know about you guys, but using WM_KEYDOWN and WM_MOUSEMOVE to detect input in OpenGL is very slow and inefficient. Is it recommended to use DirectInput with OpenGL for keyboard and mouse input? What would you guys recommend for input in OpenGL?


A lot of people when start to use OpenGL think about GL as a game library. Why?
OpenGL as the name itself tell you, is a Graphic library (Open probably makes it more cool :) .
So you can use what you prefer to detect input.
If something is slow GL is not guilty :)

My (personal) suggestion is to use SDL. I prefer simple, cross platform and open source solutions...

PS: probably you have misunderstood the usage of WM_KEYDOWN (slow???) : it requires some little tricks to do what I suppose you want.

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!