OpenGL in OS X

mrBannana
Unregistered
 
Post: #1
I have been doing a little OpenGL programming with my Mac lately and have a problem I cannot figure out. My programs do not respond to keyboard input. They are all "standard" OpenGL programs in that they will compile on any machine that has the OpenGL libraries (glut, etc.). I set up the call back routine correctly and evidence of that is when I run the same source on Windows the keyboard works fine.

Is there anything else I have to include in my programs? I use project builder, start with a C++ tool, add the opengl,glut and foundation frameworks and #include <GLUT/glut.h>,#include <OpenGL/gl.h> and #include <OpenGL/glu.h>. Still, the keyboard does not work.

The only thing that happens is when you type is the system beeps and then eventually those characters go to the console that pops up when you run any of these programs.

I get this not only in my programs but other source I have downloaded etc.

I haven't a clue as to why I am getting this behavior. Any advice is much appreciated.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
Let me guess, you're compiling your program on the command line?

There's a bug/feature in 10.2 which means that non-bundled apps that are run from the command-line can't get user focus.

The latest version of glut from developer.apple.com/samplecode works around this problem, or you can just put your app in a proper bundle. The easiest way to get your app bundled is to make a Project Builder project for it using an Application template.
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #3
If you're using the GetKeys() function to read the keyboard and your Mac hasn't been rebooted in a while, you've run into a bug in OS X. Basically, GetKeys() stops responding after a random (usually long) amount of time (caused by certain system events).
Supposedly this is something that will be fixed in the 'next major update' of OS X (ie probably 10.3)
Quote this message in a reply
Moderator
Posts: 365
Joined: 2002.04
Post: #4
Quote:Originally posted by Zwilnik
Basically, GetKeys() stops responding after a random (usually long) amount of time (caused by certain system events).

That's interesting. I've seen this happen a few times but I've never known what causes it. Do you know which system events make it happen?

Neil Carter
Nether - Mac games and comic art
Quote this message in a reply
mrBannana
Unregistered
 
Post: #5
Quote:Originally posted by OneSadCookie
Let me guess, you're compiling your program on the command line?

There's a bug/feature in 10.2 which means that non-bundled apps that are run from the command-line can't get user focus.

The latest version of glut from developer.apple.com/samplecode works around this problem, or you can just put your app in a proper bundle. The easiest way to get your app bundled is to make a Project Builder project for it using an Application template.


Actually no I am not running it from the command line. Regular old Project Builder. I have tried executing it from the command line, but it still does not work, as you noted.

I just installed the December tools (those are the latest I gather) and still the keyboard function does not respond. (I was using older tools because that's all they had at the Apple Store when I bought this Mac recentally).

Also, to reply to another poster here, I am not using getKeys(). Just the glut glKeyboardFunc() function.

Thank you all for the help though. I should note that I have got the keys to work before...I think it was some Apple code I was running....oh well, it will work eventually.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #6
If you're using a Tool project in Project Builder rather than an Application project you might see the same problem. Otherwise, I don't know. Do the GLUT examples (somewhere in /Developer/Examples/) work?
Quote this message in a reply
mrBannana
Unregistered
 
Post: #7
I got it all worked out now. I updated OS X to 10.2.4 and installed the openGL update and everything works fine now! Thank you for all your help!
Quote this message in a reply
Founder
Posts: 1,138
Joined: 2002.04
Post: #8
OSC, this is a good one for the FAQ.

Carlos A. Camacho,
Founder
iDevGames
Quote this message in a reply
MrFreak
Unregistered
 
Post: #9
Zwilink,

That GetKeys() bug has annoyed me since 10.1. And do you use GetKeys() in Airburst or are you using Carbon Events?

In my tech support incident, Apple claimed they'd fix it in 10.2.5, but I can't say for sure if they have or not as of yet...

-Mark Johns
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #10
I use GetKeys as it's the nearest thing Apple has to an actual arcade style key read (carbon events are way too slow for multiple key reads). I thought the bug was only going to be fixed in 10.3 from the response on the games dev list ?
Quote this message in a reply
Member
Posts: 440
Joined: 2002.09
Post: #11
Quote:Originally posted by Zwilnik
I use GetKeys as it's the nearest thing Apple has to an actual arcade style key read (carbon events are way too slow for multiple key reads). I thought the bug was only going to be fixed in 10.3 from the response on the games dev list ?

The "raw" key events available in the carbon seem to work well enough, modifiers are a bit of a pain though. It also helps to keep track of ups/downs in a separate keystate array regardless of the event model used (makes porting to other platforms a lot friendlier).

The biggest problem I have with getkeys is that it reads the keyboard state at the exact moment in time when it's called - that's fine if yer framerate is humming along, but you can lose keystrokes in games where a high framerate isn't guaranteed. Carbon events are queued so they'll always get processed (even if they lag a frame or two at times).

As for the getkeys bug - I'm not sure if it's fixed yet - but I read that any app that asks the user to authenticate can break getkeys system wide.
Quote this message in a reply
Moderator
Posts: 335
Joined: 2002.04
Post: #12
Quote:Originally posted by Frank C.

The biggest problem I have with getkeys is that it reads the keyboard state at the exact moment in time when it's called - that's fine if yer framerate is humming along, but you can lose keystrokes in games where a high framerate isn't guaranteed. Carbon events are queued so they'll always get processed (even if they lag a frame or two at times).


I use GetKeys() and not Carbon events for exactly that reason Smile (if drawing frame rates are likely to be low, run the GetKeys on a regular interupt). There's nothing worse in an arcade game than acting on a key event that was received several frames ago (well there are worse things, but it's very bad). If you're skipping keys, increase the balance of your CPU time towards input processing.

It's a shame that the Mac (and the PC for that matter) don't have keyboard reading capabilities like the old Amiga. One thing they got very right was that each key was an individual switch, so you could read them on and off without worrying about messages from them being blocked by other keys being pressed. Someone should do a USB gaming keyboard that works like that !
Quote this message in a reply
Member
Posts: 440
Joined: 2002.09
Post: #13
Quote:Originally posted by Zwilnik
I use GetKeys() and not Carbon events for exactly that reason Smile (if drawing frame rates are likely to be low, run the GetKeys on a regular interupt). There's nothing worse in an arcade game than acting on a key event that was received several frames ago (well there are worse things, but it's very bad). If you're skipping keys, increase the balance of your CPU time towards input processing.

I've never been able to do that reliably (got source?)
Quote this message in a reply
Post Reply