Advertisement

Creating a window for OpenGL in X11

Started by January 26, 2004 01:02 PM
8 comments, last by Ilici 20 years, 7 months ago
Well, how do i do it? All the tutorials i found use glut which i don''t want to use (i hate the glutMainLoop thingy). Oh and no SDL neither, i just want Xlib functions.. And is there an equivalent to GetKeyState from win32? or GetKeyboardState. [ My Site ] [A link to gamedev] [A Link to google] [A link to nowhere] [ /*ilici*/ ]
quote: Original post by Ilici
Well, how do i do it? All the tutorials i found use glut which i don''t want to use (i hate the glutMainLoop thingy). Oh and no SDL neither, i just want Xlib functions..

Look at the source code of SDL. It''s not too hard to read (I''ve read a decent bit of it for some insight) and it is trusted to work virtually everywhere because it''s been around for a while in such common usage.

quote: Original post by Ilici
And is there an equivalent to GetKeyState from win32? or GetKeyboardState.

I think XQueryKeymap would do what you want.

Advertisement
quote: Original post by Null and Void
quote: Original post by Ilici
Well, how do i do it? All the tutorials i found use glut which i don''t want to use (i hate the glutMainLoop thingy). Oh and no SDL neither, i just want Xlib functions..

Look at the source code of SDL. It''s not too hard to read (I''ve read a decent bit of it for some insight) and it is trusted to work virtually everywhere because it''s been around for a while in such common usage.

quote: Original post by Ilici
And is there an equivalent to GetKeyState from win32? or GetKeyboardState.

I think XQueryKeymap would do what you want.




thanks a lot! I got the SDL source for window creating and i''m gonna try it out now..

Do you know if the keys returned by XQueryKeymap are the same that Direct Input or GetKeyboardStatus would return ?
quote: Original post by Ilici
Do you know if the keys returned by XQueryKeymap are the same that Direct Input or GetKeyboardStatus would return?

I doubt that they''re similar. XQueryKeymap fills in a 32-byte array where each bit is the up-or-down state for a single key. The constants for which bit represents which key can be found in the Xlib header keysymdef.h, if that''s what you''re looking for.

The values from XQueryKeymap seem to just be an internal representation of the key events passed through the X event handler (if a key event hasn''t been dispatched, the keymap won''t be updated either, according to the documentation), so it''s unlikely to offer any "performance" benefits over just storing an array and keeping it up-to-date yourself (which is what SDL does, if you''re wondering at all), just ease-of-use for certain situations.

I've looked into XQueryKeymap, but i'm not sure how to use it. I've looked at the keysymdef.h file and i saw that the keys have 16bit identifiers like 0xFF01 which are obtained like K(Fn, Key) = (Fn << 8) | Key; Now if the XQueryKeymap returns 32 8bit chars whose bits represent the 256 keys's up / down state.

I've found a link to some assembly code to get make and break codes directly, but i can't implement the thing myself. Does anyone know of any library that does that?

[edited by - Ilici on January 27, 2004 10:29:27 AM]

[edited by - Ilici on January 27, 2004 12:15:01 PM]
The header I told you about has "key symbols" in it, not "key codes". To convert a symbol to a code you use XKeysymToKeycode. As long as the code is not NoSymbol, you can test its position in the bit vector. Here''s an example:
int test_key(Display *display, KeySym keysym, const char keys[32]) {	KeyCode keycode = XKeysymToKeycode(display, keysym);	if(keycode == NoSymbol)		return 0;	return (keys[keycode >> 3] >> (keycode & 0x07)) & 0x01;}


Advertisement
quote: Original post by Ilici
Well, how do i do it? All the tutorials i found use glut which i don''t want to use (i hate the glutMainLoop thingy). Oh and no SDL neither, i just want Xlib functions..

And is there an equivalent to GetKeyState from win32? or GetKeyboardState.



[ My Site ] [A link to gamedev] [A Link to google] [A link to nowhere] [ /*ilici*/ ]


Look at the Linux/GLX ports of nehe''s tutorials
"THE INFORMATION CONTAINED IN THIS REPORT IS CLASSIFIED; DO NOT GO TO FOX NEWS TO READ OR OBTAIN A COPY." , the pentagon
quote: Original post by Null and Void
The header I told you about has "key symbols" in it, not "key codes". To convert a symbol to a code you use XKeysymToKeycode. As long as the code is not NoSymbol, you can test its position in the bit vector. Here''s an example:



Heh, thanks, actually i wrote a program that checked all the keys and printed out the codes of the ones that are pressed and then pressed keys on my keyboard and noted the code, took a while though ..



Do it Null and Void''s way because your way will mysteriously break sometime in the future when you upgrade you X server.
quote: Original post by Ilici
Well, how do i do it? All the tutorials i found use glut which i don''t want to use (i hate the glutMainLoop thingy). Oh and no SDL neither, i just want Xlib functions..

And is there an equivalent to GetKeyState from win32? or GetKeyboardState.



[ My Site ] [A link to gamedev] [A Link to google] [A link to nowhere] [ /*ilici*/ ]


Hi!

check the "GLX" ports of the NeHe tutorials. They use nothing but Xlib.

cya,
Drag0n

-----------------------------
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning..." -- Rich Cook

My future web presence: Dave''s Programming Resources
-----------------------------"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning..." -- Rich Cook"...nobody ever accused English pronounciation and spelling of being logical." -- Bjarne Stroustrup"...the war on terror is going badly because, if you where to compare it to WWII, it's like America being attacked by Japan, and responding by invading Brazil." -- Michalson

This topic is closed to new replies.

Advertisement