MacOS X port of GLFW

Hi!

This is the continuation of a thread in the toolkits forum , but I think it is better handled here in the Mac forum (where all the gurus are )…

Intro: I am the author of GLFW , which is a portable OpenGL toolkit (primarily aimed at game development). At the moment it works on Windows and Unix/X11 (Linux, SGI/IRIX, Solaris, etc), but I (and many others) would like a Mac port of the toolkit too.

Since I do not have a Mac myself, I am forced to rely on others to do the port for me (but I want to help as much as I can, of course). For the interested, I have created a web page with some base Mac OS X sources for GLFW. Go here !

Ok, on with the show…

Since I’m new to MacOS X, I have few questions. The most critical question is: Which interface(s) should be used?

Personally, I feel that a pure MacOS X port would be OK (don’t support MacOS 9). MacOS X is also much better suited for supporting GLFW (e.g. the multi threading part). Then the question seems to be: Cocoa or Carbon?

Related questions:

  1. Can you code Cocoa from standard C? (the Apple site only mentions Obj-C)
  2. What compilers support MacOS X? Can we support them all?

To question 2, paulfjeld answered:

Apple provided IDE (free) and CodeWarrior 8.0 (expensive). (other Java, Basic as well). As long as you support the ProjectBuilder/App Builder requirements, I think Codewarrior can handle it >and< give you Classic with simple switch-throwing.

My followup questions:

  • Is there ANY way of getting threads (see GLFW manual) to work under “Classic”? Since the Unix port of GLFW uses pthread, and pthread is included in MacOS X/Darwin, it is the easiest way to go (it has already been tried by Keith Bauer, and it works).

  • GCC 3.x works for MacOS X (right?). Can it handle Cocoa etc? Can you mix the Apple IDE libs/includes with GCC? Is there a simple-to-install binary distro of GCC for MacOS X (similar to MinGW32 for Windows).

More… There seems to be a problem with libc under MacOS X, in that it does not export pthread_kill in versions earlier than 10.2. First, I’m a bit surprised to see it in libc (not a spearate lib). Second, how is libc linked? Statically or dynamically. What happens if I compile an app under 10.2 that uses pthread_kill and try to run it under an earlier version of the OS? Can I check the OS version and pop up an error message, or will the app simply refuse to start due to missing libc symbols?

I don’t see a problem with supporting only v10.2+, since upgrading seems to come at nearly no cost. I’m only interested in the consequences.

Ok, I’m sure I’ll have more questions later…

[This message has been edited by marcus256 (edited 12-13-2002).]

I am the aforementioned Keith Bauer, and these are my opinions

Little to no point in supporting Mac OS 9. OS 9 support is basically just a playground for the larger companies, and the small developers that haven’t upgraded. Even many of the major game ports are no longer coming to OS 9, because it just doesn’t offer enough OpenGL features.

If you’re only supporting Mac OS X, there’s little to choose between Cocoa and Carbon. Cocoa will be slightly easier than Carbon, and that’s what I used in my partial port. The users of the library won’t care, the users of the programs won’t care, but in Cocoa the code will be shorter and more readable than in Carbon.

Cocoa is only accessible from Objective C or Java. I fail to see why this is relevant (beyond naming source files .m rather than .c).

Metrowerks CodeWarrior and Apple GCC both support Carbon and Cocoa completely.

OS 8.6 and above support preemptive multithreading, but not particularly well I think, and the code path will be completely different. Not many people have the API knowledge to use 8.6+s MP tasks.

The Apple compiler used by the Project Builder IDE is GCC. 10.2 uses 3.1 by default, 10.1 and below use 2.95 by default.

10.1 and below don’t support pthread_kill. libc is dynamically-linked, so there’s no way to obtain that functionality on 10.1.

The 10.2 update is quite expensive, so many people have not upgraded. I would guess that most of the target audience for GLFW have upgraded, though.

Hello Keith!

Nice to hear your voice again… (eeh, you know)

I hope you don’t mind my exposing your code & name officially like this (I think you deserve some credit for the work!)

Originally posted by OneSadCookie:
Little to no point in supporting Mac OS 9.

Agree (at least from my point of view)

If you’re only supporting Mac OS X, there’s little to choose between Cocoa and Carbon. Cocoa will be slightly easier than Carbon, and that’s what I used in my partial port. The users of the library won’t care, the users of the programs won’t care, but in Cocoa the code will be shorter and more readable than in Carbon.

Yes, Cocoa seems like the natural choice. Carbon would only be useful if we want to be able to go MacOS 9 too (or if it could offer more useful functions, which I find very unlikely), but it seems more natural to skip pre-X all together.

Cocoa is only accessible from Objective C or Java. I fail to see why this is relevant (beyond naming source files .m rather than .c).

Not really a big difference. I just think that since GLFW is not an application that would benefit much from Obj-C features (the only difference I saw in your implementation was how functions were called, basically), it doesn’t matter much which language you use. With that in mind, C is a more widely used language (for instance, I would be able to do simple modifications to the sources myself, with Obj-C I’m not sure if I dare do that since I don’t know the language).

The Apple compiler used by the Project Builder IDE is GCC.

Hehe, I kind of figured that out last night (how else could Apple supply a free compiler?).

Then, what is the compiler interface(s)? Can you use Makefiles? I think Jaguar comes with a shell interface, so there you should be able to do it classic Unix-style by calling ‘make’ (which should be included in the Apple GCC distro?). I’m not sure, but is it even possible to create a nice “IDE project file” that can build the GLFW lib and several example executables with just one “click”.

The 10.2 update is quite expensive, so many people have not upgraded. I would guess that most of the target audience for GLFW have upgraded, though.

Then GLFW would just be another reason to upgrade (I know at least one GLFW-based game that is very likely to support MacOS X)

Written by 147-2:
None of the programming work that I have done on OSX used those binary project files, I used Makefiles. I am gonna have to dig up more info on OSX programming, for one, I know that all of the projects that I have done using Makefiles have been command line only, even ones involving 3d engines and so forth. I need to find out if it is possible to make “double clickable” OSX programs from a Makefile.

…which answers my question about Makefile (weehaa!)

Regarding double-clickable… Don’t know about MacOS X, but under Windows you can choose between ‘-mconsole’ (default) and ‘-mwindows’ (which does not open a console window and effectively trashes any stdout/sterr output, plus some other effects). There should be a similar switch for MacOS X (since it’s GCC), I suppose.

To be double-clickable on Mac OS X, the application needs to be properly “bundled”. Basically, that means you need to set up a directory hierarchy something like this:

MyCoolApplication.app/
    Contents/
        PkgInfo
        Info.plist
        MacOS/
            MyCoolApplication*
        Resources/
            ...

PkgInfo and Info.plist are files that need to have specific content (all described in detail on the Apple developer site).

The .app extension on the outer directory will be hidden in the Finder, the icon specified in Info.plist will be shown instead of the folder icon, and double-clicking the package will launch the executable specified in Info.plist (conventionally named the same as the package, sans .app).

Obviously, it’s entirely possible for a Makefile to set this stuff up, but if you want to be friendly to the majority of OS X’s developer community, you should really consider using a Project Builder project.

Interesting topic.

I went the Carbon way because I wanted to have a c++ interface for Gizmo3D.

You can use Makefiles with the integrated projBuilder as well. Its ok to mix them.

Just remember what Mr Cockie said about the bundle. In general you should always try to use that and avoid direct console apps whne you are dealing with events and windows (sometimes I got problems with focus and keyt input when I didn’t use bundled apps)

It’s a known bug that 10.2 won’t activate a window of a non-bundled mach-0 application, but it’s generally better practice to bundle your app anyway – that way you get double-click-ability, icon, type/creator bindings, copyright & version information, &c.

Oh, and using C++ doesn’t stop you using Cocoa, BTW. You can name your source files .mm and include both C++ and Objective-C source in the same file, if you’re willing to wait three times as long for it to compile

I’ll leave the C vs C++ argument for the thread on the advanced forum, no matter how tempting it is to slag off C++ here

Hi all, interesting info. Anyway, that probably means that the >10 example programs have to be console apps. I don’t want to bloat the otherwise neatly portable source tree with Mac specific hierarchies.

I also think C vs. C++ vs. Obj-C isn’t really the topic here. I just hope that there is no problem with mixing C & Obj-C for the MacOS X GLFW port, since the TGA/image/texture loader is written in C (common source for all platforms, so far).

Ok, to get this thing going then, it seems as if there should be no big problem with mixing the “GLFW skeleton” and the “Keith code” (renaming .c to .m etc), and do a Makefile for the whole thing. Possibly I can do most of the work myself, but I have no way of trying it out, so I hope I can get some help with that.

Idea: it should be possible to at least try to compile GLFW even on my Win/Linux PC, since I use GCC. All I would need is the Apple include files (?). I wouldn’t be able to link, but a compile check is at least something for me to work with (until MacOS X is released for Intel platforms, which will probably never happen).

I suppose I can’t just download the Apple SDK. It’s probbably not in a “PC”-recognizable .zip or .tar.gz format (?) Any ideas?

Update:

I have now created a web page for the porting project: http://hem.passagen.se/opengl/glfw/mac/

I took my best shot at it, and integrated Keiths source into the current GLFW v2.3.2 source tree. Basically, I changed the source to fit with the current layout of the Win32 & X11 sources. I also created a Makefile for building the library.

My guess is that it will not compile without errors, but it’s hopefully a step in the right direction.

Could someone please try it out, and see if it works? Modifications & fixes are welcome!

I’ve made your changes compile, I’ll email my fixes to you.

Not bundling the examples isn’t going to work, unfortunately, since on Jaguar if they’re run from the console it won’t be possible to activate their windows.

I suggest making a little MakeBundle.sh script that can be called from the makefile to generate the bundles at build time.

Some comments on the list on the website, based on the work I’ve done so fare:

  • Fix all Mac OS X related Makefiles

Well, they all work, even if there is room for improvement

  • Make a MakeBundle.sh script that creates ‘bundles’ for the example programs at build time

Pretty much done. Might need to be a bit cleverer.

  • Resolve GLFW include file location conflict (<GL/glfw.h> vs <GLFW/glfw.h> )

I was originally building GLFW as a framework, hence the framework-style include. That’s probably still the best way of distributing it, but for the moment it’s built as a static library. At that point, probably just straight “glfw.h” is the most appropriate header path. Either way, it’s not hugely appropriate for it to match the Unix standard, unfortunately. OS X programmers are already used to this, however, since GLUT is <GLUT/glut.h> and OpenGL is <OpenGL/gl.h>…

  • Iconification/restoration is not implemented

This one’s easy. Personally, I don’t agree that it should be a programmatic API (the only way a window should become iconified is through user action), but if it needs to be implemented, it’s easy.

  • Window close events are not detected

I don’t think any of the window events are handled. I guess this will come more easily once I figure out how to handle command key equivalents for the menu bar, &c. You don’t normally run the event loop programmatically like GLFW requires in Cocoa (or Carbon), you see, so some extra, somewhat unusual stuff has to be done to get the basic functionality working again.

  • Add callback for window resize events (can these be handled with normal Cocoa NSEvent events?)

Same issue.

  • Add support for accumulator buffers, aux buffers, stereo rendering and refresh rate selection/querying

All pretty easy, I think, once I know what the API is

  • glfwSetWindowSize should work in fullscreen mode too (if possible)

Should be possible. I hope it won’t require the destruction of the OpenGL context, but that’s an edge possibility.

  • Resolve keypad keys

You mean distinguish between keypad numbers and keyboard numbers?

  • Handle “de-shifting” on international keyboards

Are you doing this on Windows/Linux? How? I just don’t know how (or even if) this is possible on the Mac.

  • Check if mouse wheel implementation is correct

I don’t have a mouse wheel, so I’ll need someone else’s help with this.

  • Hiding the mouse cursor is only implemented in fullscreen mode

Deliberately! The code that’s there should work in windowed mode just fine, but it breaks every HI guideline in the book.

  • How does mouse input work in fullscreen mode?

Seems to work OK?

  • Add joystick support

HID, blech

And some more issues:

It’s crashing on exit from a windowed-mode app. No idea why at this stage.

It’s corrupting the menu bar on exit from a full-screen app. I think this one’s an easier fix. The menu bar is also active even when in full-screen mode, which has odd consequences.

The OpenGL context still looks like it overlaps the window’s title bar. I don’t think it actually does, it just looks that way. Dunno why, either – it seems like what I’m doing should work. Not quite sure how to fix it, but I have some ideas.

[b]

  • Fix all Mac OS X related Makefiles

Well, they all work, even if there is room for improvement
[/b]

Just one thing: top level makefile & cleanup?

[b]

  • Make a MakeBundle.sh script that creates ‘bundles’ for the example programs at build time

Pretty much done. Might need to be a bit cleverer.
[/b]

Seems very OK to me. Question: how is console output (printf) handled for “bundled” apps? (e.g. listmodes.c)

[b]

  • Resolve GLFW include file location conflict (<GL/glfw.h> vs <GLFW/glfw.h> )

I was originally building GLFW as a framework, hence the framework-style include. That’s probably still the best way of distributing it, but for the moment it’s built as a static library. At that point, probably just straight “glfw.h” is the most appropriate header path. Either way, it’s not hugely appropriate for it to match the Unix standard, unfortunately. OS X programmers are already used to this, however, since GLUT is <GLUT/glut.h> and OpenGL is <OpenGL/gl.h>…
[/b]

What implications would it have to go “framework”? Is it just another “archiving” tool (instead of ‘ar’). Would it be possible to have both, as with the Win32 version (static + DLL)? (some people prefer static linking)

[b]

  • Iconification/restoration is not implemented

This one’s easy. Personally, I don’t agree that it should be a programmatic API (the only way a window should become iconified is through user action), but if it needs to be implemented, it’s easy.
[/b]

Usually, yes. There is a point in being able to iconify a fullscreen window though (e.g. pop up a config window on the desktop without closing the OpenGL display, or similar). I suppose iconifying a fullscreen window is quite different from iconifying a window (see X11/Win32 sources…).

[b]

  • Window close events are not detected

I don’t think any of the window events are handled. I guess this will come more easily once I figure out how to handle command key equivalents for the menu bar, &c. You don’t normally run the event loop programmatically like GLFW requires in Cocoa (or Carbon), you see, so some extra, somewhat unusual stuff has to be done to get the basic functionality working again.
[/b]

Sorry for that… Again As you will see I did a hack in glfwPollEvents in the latest update, which asynchronously records window sizing. As long as we only have “PollEvents”, it should not be a big problem. For the planned “WaitEvents” function it would be more problematic. Unless another solution can be found, I suppose it could be solved with a Periodic NSEvent to drop out of the wait state on regular intervals for window “event” polling.

[b]

  • Add support for accumulator buffers, aux buffers, stereo rendering and refresh rate selection/querying

All pretty easy, I think, once I know what the API is
[/b]

Yes, I suppose so. I just left a few “FIXME”:s where the code should be inserted. I think it’s really easy.

[b]

  • glfwSetWindowSize should work in fullscreen mode too (if possible)

Should be possible. I hope it won’t require the destruction of the OpenGL context, but that’s an edge possibility.
[/b]

It’s not top priority. I know Orky will rely on that, but I think they have fallbacks.

[b]

  • Resolve keypad keys

You mean distinguish between keypad numbers and keyboard numbers?
[/b]

Yes. There is a NSNumericPadKeyMask bit in modifierFlags, but I’m not sure if it can be used (the docs were not very clear on wether the flag is related to the keys in the keyboard message, or if it only tells if ANY of the keypad keys is held down when the keyboard message was sent).

[b]

  • Handle “de-shifting” on international keyboards

Are you doing this on Windows/Linux? How? I just don’t know how (or even if) this is possible on the Mac.
[/b]

Windows/Linux fortunately gives me un-shifted keys (well, unaffected by the shift key anyway), if I use “the right way” (there are other problems though). Under Mac it seems very problematic. The hard way would be to query the current keyboard layout (if possible), and keep hardcoded de-shifting maps for every possible keyboard in the GLFW source.

[b]

  • Hiding the mouse cursor is only implemented in fullscreen mode

Deliberately! The code that’s there should work in windowed mode just fine, but it breaks every HI guideline in the book.
[/b]

…but the GLFW specs says it should Well, the primary intent of disabling the mouse cursor is to be able to use the mouse as a game control device (i.e. not being limited by the window/screen borders). If a game is to be runnable in windowed mode, you must be able to give the game exclusive access to the mouse - period. In the win32 version of GLFW, you will get the cursor back if you ALT-TAB out of a GLFW window with a hidden mouse cursor, so it’s not 100% stolen.

This is an old issue popping up again - is it possible to control the position of the mouse cursor under Mac OS X? I seem to remember that you said that there were hideous delays resulting from such attempts. Is there an alternate mouse interface that can be used (more down-n-dirty closer-to-hardware-level)?

[b]

  • Add joystick support

HID, blech
[/b]

Not top priority. This is a typical part of the GLFW source that can easily be broken out of the rest of the code, and can be handled by someone with a keen interest in joysticks


It’s crashing on exit from a windowed-mode app. No idea why at this stage.

Check your window resources in glfwCloseWindow? (I noticed the function is kind of thin?)

Ok… Anyway, all this is great work and great news. We’re rolling!

Curiuos question: Is there ANY difference between Cocoa and OPENSTEP/NeXTStep?

[b]- Fix all Mac OS X related Makefiles

Just one thing: top level makefile & cleanup?[/b]

eh?

Question: how is console output (printf) handled for “bundled” apps? (e.g. listmodes.c)

The issue isn’t bundled vs non-bundled (there’s no difference as far as the OS is concerned), but Finder-launched as opposed to command-line-launched. If the app is run from the command-line, the standard Unix thing happens. If the app is run from the Finder, standard output goes to a log file somewhere, which can be viewed in real time via the “Console” application.

What implications would it have to go “framework”? Is it just another “archiving” tool (instead of ‘ar’). Would it be possible to have both, as with the Win32 version (static + DLL)? (some people prefer static linking)

Obviously, keeping a static link option is nice. A framework is a bundle which contains (possibly multiple versions of) a dynamic library, its headers, documentation, dependent resources, &c. It’s Mac OS X’s answer to the /usr/include /usr/lib /usr/share mess that is typical of Unices. Frameworks can be included inside an application’s bundle, too, so there’s no need for a separate install in general.

Usually, yes. There is a point in being able to iconify a fullscreen window though (e.g. pop up a config window on the desktop without closing the OpenGL display, or similar). I suppose iconifying a fullscreen window is quite different from iconifying a window (see X11/Win32 sources…).

You won’t be able to iconify a full-screen window on Mac OS X (there is no window for a start). It should be possible to un-capture the display and return to the desktop mode without killing the OpenGL context, but iconification is not the way Of course, I can implement full-screen iconification to do precisely this, but it won’t produce an iconified window anywhere!

- Window close events are not detected

I think you misunderstood what I meant by my answer to this question. Window events (including live resize events) shouldn’t be a problem, once I figure out how to receive them… In a normal Cocoa application, that all just happens automatically. Because GLFW is handling the event loop itself, however, it’s not quite automatic any more.

Yes, I suppose so. I just left a few “FIXME”:s where the code should be inserted. I think it’s really easy.

OK, I’ll have a look for those.

There is a NSNumericPadKeyMask bit in modifierFlags, but I’m not sure if it can be used (the docs were not very clear on wether the flag is related to the keys in the keyboard message, or if it only tells if ANY of the keypad keys is held down when the keyboard message was sent).

You very seldom get more than one character per key event (though you might for foreign scripts, I guess). I’d guess that this mask can be used. I’ll try it out.

  • Handle “de-shifting” on international keyboards

The hard way would be to query the current keyboard layout (if possible), and keep hardcoded de-shifting maps for every possible keyboard in the GLFW source

There’s no need to get that extreme! At the very least, we ought to be able to use the raw key code from the key event rather than the characters, and use the system’s key mapping to go from there… won’t be pretty, though

…but the GLFW specs says it should Well, the primary intent of disabling the mouse cursor is to be able to use the mouse as a game control device (i.e. not being limited by the window/screen borders). If a game is to be runnable in windowed mode, you must be able to give the game exclusive access to the mouse - period. In the win32 version of GLFW, you will get the cursor back if you ALT-TAB out of a GLFW window with a hidden mouse cursor, so it’s not 100% stolen.

Yeah, but that doesn’t stop the fact that it’s appalling HI. If you’re in windowed mode, standard UI elements like the menu bar and window widgets are visible and should be usable. If you want to make them unusable, you need to disable them somehow, and the way to do that is full-screen mode.

If the program is using the mouse for input in a way that’s not appropriate for windowed mode, it needs to go to full-screen.

And what happens when the mouse is hidden but they can still use the window widgets, the menu bar, and activate other apps by clicking outside the window?

This is an old issue popping up again - is it possible to control the position of the mouse cursor under Mac OS X? I seem to remember that you said that there were hideous delays resulting from such attempts. Is there an alternate mouse interface that can be used (more down-n-dirty closer-to-hardware-level)?

You can’t (and shouldn’t) control the position of the mouse, for the same sorts of reasons as above. There are functions that move the mouse cursor, but they lock it down for a fixed period afterwards, during which no mouse moved events can be generated. The period is programmatically adjustable to zero, however, so that’s not so much of an issue.

The “right” way of doing this is to get mouse deltas (unconstrained by screen bounds) out of the mouse moved events. That way you have no need to move the cursor around.

On Jaguar, the mouse is accessible via the HID manager, but I don’t think mouse scaling has been applied by then, so the values you get back from that interface are probably not compatible with the actual movements of the pointer on the screen.

Check your window resources in glfwCloseWindow? (I noticed the function is kind of thin?)

I have looked at this, and I think I’m doing everything I need to, and in the right order. Obviously I’m wrong

Curiuos question: Is there ANY difference between Cocoa and OPENSTEP/NeXTStep?

Apple has Mac-ified it a bit, and added some new functionality (sheets, drawers, OpenGL, &c) – but it’s very close to the original interface.

[b]- Fix all Mac OS X related Makefiles

Just one thing: top level makefile & cleanup?

eh?
[/b]

Didn’t see any cleanup of the bundles in the top level makefile (in the root of the distro). Have you tried it?


You won’t be able to iconify a full-screen window on Mac OS X (there is no window for a start). It should be possible to un-capture the display and return to the desktop mode without killing the OpenGL context, but iconification is not the way

That’s how it’s done under Win32 & X11. That’s how I expect it to be done (every OS I know of except AmigaOS has to do it that way).


Of course, I can implement full-screen iconification to do precisely this, but it won’t produce an iconified window anywhere!

Can one create a dummy icon/window? This can perhaps even be done at glfwOpenWindow?

[b]- Window close events are not detected

I think you misunderstood what I meant by my answer to this question. Window events (including live resize events) shouldn’t be a problem, once I figure out how to receive them…
[/b]

Well, after reading the Cocoa docs (foundation and appkit) I didn’t find any such info. It seems to be left out. Perhaps I’m looking in the wrong place?

[b]There is a NSNumericPadKeyMask bit in modifierFlags. [snip]

You very seldom get more than one character per key event (though you might for foreign scripts, I guess). I’d guess that this mask can be used. I’ll try it out.
[/b]

We can perhaps live with the very unlikely bug of getting a keypad key and a non keypad key in the same message? Especially if we filter against numeric/arithmetic keys, the chanses should be minimal. (?)


There’s no need to get that extreme! At the very least, we ought to be able to use the raw key code from the key event rather than the characters, and use the system’s key mapping to go from there… won’t be pretty, though

Are the key codes portable?? (I mean, between different keyboards)


Yeah, but that doesn’t stop the fact that it’s appalling HI. If you’re in windowed mode, standard UI elements like the menu bar and window widgets are visible and should be usable. If you want to make them unusable, you need to disable them somehow, and the way to do that is full-screen mode.

I don’t want to argue with you. I agree. But there are many situations when windowed mode is preferrable to fullscreen mode (e.g. during development & testing, for systems with “nView” etc). Disabling mouse input for those situations would be a pity.


And what happens when the mouse is hidden but they can still use the window widgets, the menu bar, and activate other apps by clicking outside the window?

That is up to the GLFW implementation In the X11 version, this is what is done:

  1. Load a blank cursor (= hide it)
  2. Confine mouse cursor to the window area (part of the X protocol)
  3. Respond to delta mouse moves by centring the mouse cursor (middle of the window)

…gotta go (my son just woke up)

/Marcus

[QUOTE]Originally posted by onesadcookie:
Please, Paul, join the discussion on the Mac forum that Marcus has linked to. I’d be interested to know how useful the current state of the Mac port is, and which bits I should be focusing my energy on.

You guys are blasting so fast and well my iMac purchase can’t keep up - I don’t have one yet! Since September (Jaguar) I’ve been mooning around like a switcher wanna-be, checking out what I’d need to port my projects to the Mac: a simple, easy, portable OGL toolkit! I know GLFW will be it.

By next spring I’ll be able to jump in but, at this rate, you’ll have done the heavy lifting!

The only thing that makes me nervous is joystick code on the Mac. I can’t believe Apple didn’t replace the sprocket stuff so, please, save us from the HID!

Cheering whistfully from the sidelines,

Paul

Continuing reply…


If the program is using the mouse for input in a way that’s not appropriate for windowed mode, it needs to go to full-screen.

That may be valid for an environment where you can switch video modes freely (like Mac OS), but remember that there are many X11 stations out there with a fixed desktop (=fullscreen) resolution. The standard on such systems has always been to run games (even Doom & Quake etc) in windowed mode. You don’t want to force the game to run in 1920x1440x32 if the HW can’t support vivid realtime rendering in such high resoltutions.

The key here is that GLFW is a multi platform toolkit, so we can’t limit the toolkit functionality to something that fits only one environment. I think we will have to live with “non-native” behaviour to some extent. Hopefully the GLFW docs can inform coders of the “danger” to use certain functions (like is the case for glfwDestroyThread).


You can’t (and shouldn’t) control the position of the mouse, for the same sorts of reasons as above. There are functions that move the mouse cursor, but they lock it down for a fixed period afterwards, during which no mouse moved events can be generated. The period is programmatically adjustable to zero, however, so that’s not so much of an issue.

Then it can be done… It sounds very similar to the hack/workaround that had to be done under Win32 to force a window to become the foreground window (=get input focus and end up on top of other windows), which is strictly necessary for a fullscreen display. Basically a timeout limit had to be set to zero for it to work.

In my opinion, this is not really a question of what the programmer should be allowed to do. For some applications, the intended HI is not always relevant. For instance, an action game is by nature an application that requires the users full attention all the time. Things like how menus and widgets work are of very little interest to a player in the middle of a game.

I do not want to promote badly behaving applications, but I want to give the power to do things that are necessary for games and similar applications.


The “right” way of doing this is to get mouse deltas (unconstrained by screen bounds) out of the mouse moved events. That way you have no need to move the cursor around.

That works in fullscreen mode. In windowed mode it would not work unless you manually constrain the cursor to be in the window client area. This can either be done by manually continously centering the cursor (as done for X11 & Win32), or by using OS functions to force the cursor to lie within the client window area (as is done under X11). Delta mouse moves are of course a powerful tool - but we need to prevent the user from clicking in other windows than the GLFW window.


On Jaguar, the mouse is accessible via the HID manager, but I don’t think mouse scaling has been applied by then, so the values you get back from that interface are probably not compatible with the actual movements of the pointer on the screen.

That may not be an issue. I do not expect programs to rely on the mouse coordinates to be window related when the mouse cursor is hidden. Anyway, if constantly centering the mouse cursor is the solution to prevent undesired “GUI clicks” etc, we won’t have to use HID (delta moves should work fine).

I have to check out this HID thing… What makes it so bad? (Pauls words kind of scared me)

One more thing: is Jaguar equal to 10.2? Or is it an extension?

I downloaded the HID docs. It seems to be just another interface. Not as neatly packaged as Cocoa, but that “only” means more code - which is exactly why we want toolkits like GLFW, right?

Didn’t see any cleanup of the bundles in the top level makefile (in the root of the distro). Have you tried it?

Oh yeah, make clean. No, I haven’t touched that. Should be a simple case of rm -rf

Can one create a dummy icon/window? This can perhaps even be done at glfwOpenWindow?

Should be doable. We can probably even copy the contents of the OpenGL view into the dummy window, so the miniaturized window looks right.

Well, after reading the Cocoa docs (foundation and appkit) I didn’t find any such info. It seems to be left out. Perhaps I’m looking in the wrong place?

NSWindow deals with turning mouse events into window close (&c) events, which it then sends to its delegate (and, I think, to the notification center).

Are the key codes portable?? (I mean, between different keyboards)

The key codes are portable, but I don’t know whether it’s by layout or by function that they’re portable. I believe layout. Anyway, it doesn’t matter if they’re portable or not – the system knows how to interpret them, so if we use the same information it has…

I don’t want to argue with you. I agree. But there are many situations when windowed mode is preferrable to fullscreen mode (e.g. during development & testing, for systems with “nView” etc). Disabling mouse input for those situations would be a pity.

All right. I’ll do it. But I won’t like it!

1) Load a blank cursor (= hide it)
2) Confine mouse cursor to the window area (part of the X protocol)
3) Respond to delta mouse moves by centring the mouse cursor (middle of the window)

Sounds reasonable. I guess I’ll do something similar for Mac OS X.

I have to check out this HID thing… What makes it so bad? (Pauls words kind of scared me)

I think it’s roughly equivalent to DirectInput – that’s what various people have said. All I know is that OS 9’s solution to the same problem (InputSprocket) was much easier to use!

One more thing: is Jaguar equal to 10.2? Or is it an extension?

Jaguar is 10.2’s code-name.