Input Without WindowsAPI?

Hi. I recently started playing around with openGL under Windows. I used XNA for my games previously, and in XNA, you called methods to see if the mouse was clicked, whether a key was down or not, etc. In opeGL, though, I haven’t found any of that:\ I know that you have to use the events in the WinAPI, but that gets messy and disorganized. And not only that, the WM_KEYDOWN event has that delay in the beginning. Is there any way to use methods to get input (or maybe some other way that can be used in the “game loop”)? Thanks in advance.

In opeGL, though, I haven’t found any of that

Of course not. OpenGL, as the name suggests, is for graphics. It doesn’t deal with input, nor is it supposed to.

There are a number of libraries for dealing with input online.

Try either glut, or wxWidgets (they have an opengl canvas). Or Qt (also has a gl canvas).
Windowed programming is messy pretty much any way you cut it, tough, imho. Convervation of messiness. Changing gui libraries just transfers the messiness from here to there :slight_smile:

For mouse input on Windows I believe DirectInput is still viable, despite the fact that MS recommend against using it.

Reasons why.

Firstly it’s more or less guaranteed to be on any Windows PC from the last 10 or so years. No additional library installation, no user headache, just clean and easy.

Secondly it has very comprehensive support for both recent and legacy versions of Windows. (The current recommended approach of using Raw Input has this problem, among others.)

Thirdly it doesn’t have the latency that bedevils Windows messages, where the time from when an even occurs (use clicks a mouse button) to when the message is recieved by your window procedure (WM_LBUTTONDOWN, for example) is variable and indeterminable.

Fourthly it’s actually a very clean and easy API to use.

Fifthly, as an older API it is very well understood and very well documented, with lots of sample code available in both the DirectX SDK and on the web. (Raw Input is also quite old these days, but some of it’s documentation and examples are still either ambiguous or flat-out incorrect. Once you know what to do it’s OK, but actually getting to the point where you know what to do is more of a hurdle than it should be.)

Sixthly, it’s more or less a de-facto “standard” for input devices on Windows. Everything works with DirectInput, there are no funnies, no hacks or workarounds needed, it’s predictable.

So long as you understand that it does bypass your mouse control panel settings, so therefore you’ll get no pointer ballistics, (and that this is behaviour you want), and so long as you play nice and use a non-exclusive background co-op level, there’s nothing actually wrong with using it.

For keyboard input have a look at GetAsyncKeyState, which is probably all you need there. DirectInput can also be used for keyboards, but GetAsyncKeyState does the very same with less code overhead.

i have try glut but the problem it’s more complex to install

You speak for the ages old original GLUT 3.7, or the maintained drop-in replacement FreeGLUT, which should be much easier to ‘install’ ?

Difficult?
Put the DLL where your exe is.
Put the .h file in your compiler’s header folder.
Put the .lib file in your compiler’s library folder.

The same applies to all other DLL libraries.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.