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

Cross-platform Input?

Started by Promit Jul 14, 2003 at 4:04 PM 15 replies 2.1k views
Original Post
Promit
Promit
I'm working on a cross-platform cross-compiler game project right now, and I've managed to create networking and graphics source files that compile for both Win32 and Linux (other platforms are theoretically supported, but they're essentially irrelevant). Now I'm up to input. Now we're using GLUT at the moment, and that's been very nice in terms of input. Unforunately, I don't think the GLUT input will cut it. It's event based and AFAIK it can only process one keypress at a time. I was hoping for something equivalent to Win32's GetAsyncKeyState under Linux. I have frankly never coded Linux, and I'm probably not going to do this block of code, but I'm still doing the research for it. In short, does Linux have an equivalent of Win32's GetAsyncKeyState? P.S. GLUT is the only lib we're using. Unless there is an OpenIL already I'd like to avoid pulling in any other libraries, such as SDL or whatever. [EDIT]Whoa! There IS an OpenIL...although it's conveniently still in the planning stage
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Sneftel
Sneftel
*shudder* GLUT.

I hate to tell you this, but sooner or later you''re going to have to abandon GLUT. It works fine as an OpenGL testbed, or for learning, but as you are beginning to find out, it is extremely limited. I very much doubt that GLUT will play nice if you try to do input any way other than using GLUT, so that''s probably not an option. GLUT just wasn''t intended for games.

Dump GLUT like an ex-lax milkshake and go with SDL, is my recommendation. You''ll continue to bang your head against GLUT as your application gets more complex and featureful.


How appropriate. You fight like a cow.
Promit
Promit
Did you read a single damned word I said?

GLUT is fine because I need to create a window. The window does not have to do anything, nor does it need to have anything on it except ogl.

What I need is this input routine for Linux!
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Interim
Interim
I think he was just sharing his experience with GLUT. =)

Have you looked into wxWindows? In many cases they try to use the underlying API under their wrapper API. I don''t know specificly about AsyncState, but it might have it, but then again, you question was about keyboard input that handles more than one keypress at a time?

Go to the document section, then browse through functions and find the KeyEvent. There might be other ways as well.

http://www.wxwindows.org/
Promit
Promit
...look, the entire idea is to do this _natively_, i.e. WITHOUT adding more libs!
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Sneftel
Sneftel
GLUT not only creates a window, it registers that window's MsgProc routine. So there's no way to grab arbitrary windows messages. Furthermore, it encapsulates the hWnd, so that's another raft of functionality you don't have access to. Bottom line: GLUT will actively prevent you from doing this stuff... it isn't just "stuff you use something besides GLUT for", its "stuff you can't do if you're using GLUT for anything".

I find your hostility rather off-putting... if you mouth off again, I'm not going to continue trying to help you. Getting asynchronous input is somewhat difficult in both windows and linux is slightly more difficult (and the way X-windows works means you don't have anything like GetAsyncKeyState that's window-independent), and so it's a great opportunity to use a cross-platform library. Here's my advice: if you only want one external library in your software, you picked the wrong one. Go with SDL.


How appropriate. You fight like a cow.

[edited by - sneftel on July 14, 2003 6:10:45 PM]
JulianSpillane
JulianSpillane
You know, it would be nice to be curteous to those trying to help you instead of spitting in their faces.

As Sneftel said, GLUT not only creates the window, it encapulates its hwnd so obtaining input from a source other than GLUT will be difficult and needlessly aggravating. I also reccommend abandoning it for SDL in its place. It''s smaller in file size and much more accommodating for games. But hey, feel free to spit in my face, too.
Julio
Julio
you may want to convert your project to SDL. It''s input features are very nice. depends on how far along you are in your project, but converting really isn''t that hard.

My Homepage
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Promit
Promit
Sorry, I''ve been pretty edgy today.

I''m still not switching to SDL, due to a team decision based on many factors which I won''t go over here(yes, I''m not alone).

So ultra-short version: Is there anyway to get window-independent asynchronous keyboard input in Linux? I don''t mind if it''s ugly, as long as it''s not an outright hack.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Sneftel
Sneftel
quote:
Original post by Promit
So ultra-short version: Is there anyway to get window-independent asynchronous keyboard input in Linux? I don't mind if it's ugly, as long as it's not an outright hack.
Not without root access. X-Windows is specifically built to keep you from doing this. The only thing I can think of is a really tiny non-GLUT window that would keep focus..... but that's an outright hack, and is apt to look very very bad with most WMs.

You don't have to use SDL. But you DO have to not use GLUT, at least not in its entirety. Have you considered integrating the bits of GLUT you need into your code, and adding whatever else is necessary?


How appropriate. You fight like a cow.

[edited by - sneftel on July 14, 2003 6:33:18 PM]
Promit
Promit
O...k...

So, I need some way of getting fairly reliable input without pulling in other components (this is an extremely important point, btw--I want to avoid adding anything else if at all possible!). The ideal behavior would be that I can query the status of the entire keyboard and put it into a byte buffer, much like with simple DirectInput code. Event based would be fine, but I''d need some way of processing more than one keypress per frame.

Ideas? Again, this basically only needs to work on Win32 and Linux, at least for the moment
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Jan Wassenberg
Jan Wassenberg
To the people extolling the virtues of SDL: true, but irrelevant.
BTW, GLUT will take you surprisingly far.

Your event handlers have to be called for each event pending in a given iteration of the main loop, otherwise events will lag behind. Just update your own keyboard state buffer with each up/down event (and disable key repeat).
E8 17 00 42 CE DC D2 DC E4 EA C4 40 CA DA C2 D8 CC 40 CA D0 E8 40E0 CA CA 96 5B B0 16 50 D7 D4 02 B2 02 86 E2 CD 21 58 48 79 F2 C3
Promit
Promit
Ok, I''ll mess with it.

One other thing: What about mouse input?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
Promit
Promit
Ahhhh!!

Ok, I need to get all the key events that have occurred at any time. Thus I need the events to be queued up (which GLUT does) and I need to be able to flush the entire queue (which I don''t know how to do). By flushing the entire queue I can at least get all the key messages and so not miss key presses.

How do I flush the queue? Can I even do it?
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
stodge
stodge
quote:
...look, the entire idea is to do this _natively_, i.e. WITHOUT adding more libs!


So you want cross input using native libraries? Looks like you''re writing your own then. Cross platform and native in the same sentence tends to be a misnomer unless you''re writing your own library.
---------------------http://www.stodge.net
Promit
Promit
Ok fine forget everything I said, just somebody tell me if I can somehow flush the GLUT event queue?

(in desperation mode)
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
C-Junkie
C-Junkie
http://tronche.com/gui/x/xlib/input/XQueryKeymap.html

equivalent

Topic Locked

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

Sign in to reply to this topic.