Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectInput + OpenGL?

Started by MrDoomMaster Sep 10, 2005 at 6:53 PM 3 replies 1.5k views
Original Post
MrDoomMaster
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? Thanks!
Mike.Popoloski
Mike.Popoloski
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.
Mike Popoloski | Journal | SlimDX
Drew_Benton
Drew_Benton
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.
blizzard999
blizzard999
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.
hplus0603
hplus0603
WM_KEYDOWN and WM_MOUSEDOWN are not slow at all. Many fast, popular games use them. You just gotta use them right -- see problem 2 in this link about Windows message loops.

However, you can use DirectInput if you want; there's nothing preventing you from using that together with OpenGL.
enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.