GLUT keyboard input (special keys vs ASCII keys)

1,006 views
Skip to first unread message

Floh

unread,
Jan 7, 2014, 7:04:35 AM1/7/14
to emscripte...@googlegroups.com
Hi,

I've stumbled across something which looks like a bug to me in the library_glut.js input code, but it could also be a misunderstanding on my side resulting from the many GLUT versions floating around (GLUT, FreeGlut, OpenGlut, ...):

In this commit the backspace and delete keys had been added as special keys: 


The delete key returns the special key code 111 (0x6F) and 120 (0x78).

But there are missing GLUT_KEY_xxx definitions for these in GL/freeglut_std.h , now the "official" GLUT doc states that these keys are not returned as special keys, but as ASCII code in the normal keyboard callback function:


at the end it states:

"Note that the escape, backspace, and delete keys are generated as an ASCII character."

The latest freeglut_ext.h (downloaded from here: http://sourceforge.net/projects/freeglut/) has one definition for the delete key at 0x6F, but none for 0x78 (which would be backspace):

#define GLUT_KEY_DELETE 0x006F

So long story short:

1) it looks like GLUT and FreeGLUT don't agree on how to handle the Delete key :/
2) the Delete key in FreeGLUT is only defined in the freeglut_ext.h header which we don't ship with
3) FreeGLUT doesn't define a special key code for Backspace anywhere, but  library_glut.js returns it as a special key code

I see 2 possible solutions:

1) go with the GLUT standard, remove Delete and Backspace as special keys, and return them as ASCII code (I would prefer this solution, but it breaks prenaux' change)
2) add the 2 more GLUT_KEY definitions to freeglut_std.h, GLUT_KEY_DELETE (normally defined in freeglut_ext.h, but we can't include this because 99% of the stuff in there isn't implemented in library_glut.js), and GLUT_KEY_BACKSPACE, which would be totally non-standard (neither GLUT nor FreeGLUT).

Advice? :)
-Floh

Alon Zakai

unread,
Jan 8, 2014, 7:34:03 PM1/8/14
to emscripte...@googlegroups.com
Not sure I followed all those details (I hardly know anything about glut ;), but I think we should make a testcase that works when built natively using our headers and the relevant native library, and then fix things so it works when compiled by emscripten as well.

Or is the issue that there is no clear native library to use, it can be either GLUT or FreeGLUT, and the code that works is different among those two? If so, is one of those two overwhelmingly more commonly used?

- Alon



--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Floh

unread,
Jan 9, 2014, 7:50:51 AM1/9/14
to emscripte...@googlegroups.com
Here's a short version, it's a bit of a mess really :)

- FreeGLUT seems to treat the Delete key as a special key, while GLUT treats it as a "normal" ASCII key 
- FreeGLUT has a GLUT_KEY_DELETE define for the Delete special key, BUT only in the freeglut_ext.h header, which emscripten doesn't ship with (which makes sense freeglut_ext.h has a lot of extra stuff which shouldn't be in emscripten)
- Backspace seems to be a normal ASCII key both in GLUT and in FreeGLUT, but the current emscripten implementation returns it as a special key, not as ASCII

Cleaning this up is hard without breaking existing behaviour (at least the backspace key should go from the special key callback over to the ASCII key callback).

I'll see if I can write a little native+emscripten test on the weekend and open a pull-request for further discussion.

I now tend towards going with FreeGLUT behaviour, since this is the header emscripten ships with...

Cheers,
-Floh.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

Alon Zakai

unread,
Jan 9, 2014, 1:46:32 PM1/9/14
to emscripte...@googlegroups.com
Makes sense, I tend to freeglut as well then. Hoping there is a glut expert listening here though :)

- Alon



To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages