View Full Version : mac glut questions

04-23-2007, 08:43 PM
First, when I call glutLeaveGameMode from game mode, then I get the black screen of void. Does this work properly? Recalling enter game mode to change resolutions works properly.

Another question. I have a Nyko Air Flo SX Joystick. Really nifty with the fan and all. Anyhow, when I start glut the joystick is not captured. How does one capture the joystick? I set glutJoystickFunc with the appropriate callback and time period. The usb joystick was plugged in before I started the program. If I'm not in game mode, I can get to the glut preferences window. As soon as I open this preferences window the joystick gets captured and my callback gets called. Unfortunately, when I'm in full screen game mode, I don't think the user can get to this glut preferences window nor should they have to -- not to intuitive to get there.

Just using the default joystick software in mac os x glut detects a Honey Bee AIRFLO.

Thanks for any suggestions in advance. :)

04-24-2007, 02:43 AM
I recall from a *long* time ago a bug with glutLeaveGameMode. I don't recall it being fixed.

The joystick thing seems like a bug, too. You should file them with Apple if you care about them.

Source to an older version of GLUT is available from developer.apple.com, you could fix them yourself if you care that much... but shipping software using GLUT is definitely not recommended; it was not designed for that purpose.

04-24-2007, 08:25 AM
I got the joystick to work.

The strange thing is glut detects the joystick initially. I thought the software was pre installed on the system because it detected it. In that case, I had the problems. I installed their latest software overwriting the system default. Seems there is an additional program in the doc that monitors the opengl app. With those changes I got the joystick to work in game mode. Sure beats key controls.

One other issue. When the opengl program gets the xyz triplet, some of the numbers are pre biased. For instance, if I do not move the joystick, x and z are always 3. y is 127. Looks like x and z follow the standard but y has a range of 0 to 255 but idles on 127. Sure hope this is not different for different joystick venders. I think the man page says these values should be -1000 to 1000. Buttons seem not to be a problem. Though, I get button repeats -- reminds me of a circuit class were we made one shots...

04-24-2007, 02:54 PM
Hmm, just for kicks I got a Logitech dual action gamepad. Now this works like the initial situation I encountered. Once detected it works fine. User is out of luck in this case. Of course, Vista is fully supported etc. Yet, there is the mac icon on the product. It sorta works I suppose.

Ya, I saw the glut.dmg file at apple. Looks like its vintage 2003 code. Wouldn't be wise to bundle glut because the next os or update might have improvements.

I just poll GLUT_HAS_JOYSTICK every ten seconds. If the joystick is there then I install the callback. Otherwise, set the callback to null. Seems reasonable.

I notice if one pulls the plug on the joystick, then glut still reports a joystick but the call back receives ( -1000, 0 , -1000 ). Plugin it back in will not fix the state and the program would need to be restarted.

Sort of fun to investigate....

04-25-2007, 11:30 AM
Hmm, one last mac glut question.

When I call glutEnterGameMode with a screen resolution change on my ati card everything works fine. If I call the same thing on an nvidia card on my intel mac, then I just get the background clear color drawn. Man pages says gl state is lost. So, I try to save the state but this does not work either. I reset all my callbacks. So, mouse, keyboard, blitting images to the screen from client memory works. Its just 3d drawing that is not working. Display lists are not going to be destroyed?


04-26-2007, 02:33 AM
I don't think that'll work.

You're getting a completely different context, so it has no memory of any calls you made beforehand.

It *may* be sharing resources with the regular window, in which case textures, display lists, etc. would remain, but I wouldn't count on it.

04-26-2007, 06:38 AM
Your right. I have to reload all my textures etc when the resolution changes. That appeared to correct most of the problems. I suppose most people tend to change the resolution when they start -- not much loaded in at that point.

There are some spurious situations when trying to get the joystick working. In addition, I check that the button was pressed once to key off of. Seems like the mask value is a good detector of the presence of the joystick. That is, make sure the mask is not zero at least once before ones program handles the joystick console.

05-04-2007, 05:58 PM
Well, I put in an abstraction layer for glut in my program. With that, I put in a new cgl based windowing system with carbon event handlers. I suppose a more mac oriented approach. :)

Some issues though. First, if I turn the gcc 4 compiler to -03 multisample/fsaa capability does not appear on my g5! If I turn the compiler option to -02 then it appears and opengl is multisample capable. :cool: Must be a code position thing in a universal build?

Also, from the GLCarbonCGLFullScreen demo project, I note that fonts are made with old toolbox calls like gworld etc. It looks nice but the compiler says these are depreciated? Is there another alternative to generating fonts? I guess I could use freetype but does that require x be installed? Hmm, something simpler...

05-04-2007, 06:18 PM
No idea why the -O3 thing would change things (unless there's a bug in your code that -O3 is showing up), but -O3 slows most code down, anyway. -O2 is the right choice for 90+% of the code in your program.

Draw some text in a CGBitmapContext and create a texture from that.

Using NSView is probably easier, but you seem to have discarded Cocoa for some reason.

Duplicating the old Windows/X11 scheme of a set of display lists with a DrawPixels for each character is probably not much fun; I'd switch the text rendering on other platforms to go via a texture too. The per-character approach has problems with many non-English languages (Chinese isn't really feasible due to the sheer volume of characters required; Arabic is very hard due to context-sensitive shaping and right-to-left ordering; etc.) which the texture approach doesn't suffer from.

05-07-2007, 10:19 AM
Well, I got most things ironed out now without glut. I can change resolutions without program restart etc. I added some monitor fade code and preserve the color sync settings. Got the HID stuff working too. glut seemed to have issues with devices. Works well using cgl and hid directly.

There is just this multisampling thing.

Problem is, there is some code called glCheck.h and glCheck.c. Digging deeper, the code uses quickdraw to find the devices. From this its building up a temporary context and checking for glExtensions. Well, on intel, this is deprecated code and returns multisampling not available. Its a chicken and the egg type problem. I need something likel:

bool multisample = glGetString(GL_EXTENSIONS), "GL_ARB_multisample"); //this blows when no context.

But can't do that because no more quickdraw. I wonder if I do call CGLChoosePixelFormat with samples anyway, is it going to blow on a card with no multisampling? Or do I let it fail and try again with no samples?

05-08-2007, 04:11 AM
Sounds like you want to enumerate the renderers, looking for one that supports multisampling, and falling back to one that's merely accelerated.

CGLQueryRendererInfo, CGLDescribeRenderer with kCGLRPMaxSampleBuffers, and creating a pixel format with kCGLPFARendererID should do the trick. Make sure you match the renderer to the display in a multi-display setup.

05-08-2007, 11:34 AM
I got it to work. Hmm, setting the samples higher makes a nice difference!

Thanks for the tips!