Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Sample GL code for Mac that doesn't use glut

  1. #1
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Sample GL code for Mac that doesn't use glut

    I'm buying a Mac for my niece and it should arrive in a few days. Before giving it to her I'll get some chance to play with it for about a week and I thought I should use the opportunity to add Mac support to my framework. So now I'm looking for some sample code I could use as a starting point to learn how to setup OpenGL. I want code that's interfacing the Mac GL system directly and not some kind of abstraction like glut. Unfortunately, I've been googling like mad for several hours and pretty much everything I find it glut based. Does anyone have know of any simple example code that just opens a window, creates a GL context and maybe renders a triangle or something along those lines and is not using glut?

  2. #2
    Member Regular Contributor
    Join Date
    Sep 2000
    Location
    Inside an xbox
    Posts
    290

    Re: Sample GL code for Mac that doesn't use glut

    I was trying to do that too some time ago!

    Basically you have five options:

    1) Use Cocoa. That uses Java or Objective C ( this one can be a very strange language if you come from C/C++ btw! Hopefully you can mix C/C++ with Objective C in the same way you can mix C++ and MC++, that's called Objective C++ btw ). Think in Cocoa like the Apple's version of .NET. You can use very easy the Interface Builder and use the pre-built OpenGL Cocoa control to init an OpenGL viewport. I don't recommend you that to start though, specially if you don't know Objective-C well.

    To see a very simple Cocoa+Interface Builder(NIB files) go to:
    http://www.youtube.com/watch?v=pReuTG_w-ME

    To learn the basics of Objective-C see:
    http://www.otierney.net/objective-c.html

    2) Carbon. The old C Macintosh API. Looks like MFC/Win32 API. Can be an option. You can use the aglXXXXX calls to setup the render context, choose pixel format, etc... See http://developer.apple.com/documentation.../uid/TP30001068

    Just create a new window using this
    http://developer.apple.com/documentation...CH206-TPXREF149

    and then init OpenGL with the aglXXXX functions.

    You can use the Interface Builder with Carbon too but, in that case, it won't generate code like does with Cocoa ( will be reduced to a simple GTK Glade/Gazpacho workflow without code generation, and you will need to add the event/signals manually ).

    3) GLUT. ( I know, you don't want it! ).

    4) The MacOSX 10.4 DVD allows you to install X11. Use the GLX as if you were in linux, works perfectly! ( in fact you can use the glxinfo and glxgears in MacOSX to test OpenGL! )

    5) Java. MacOSX comes with a superfast JVM and Xcode supports it plenty. Just use any existing OpenGL wrapper.

    For more information and examples see:
    http://developer.apple.com/documenta...ide/index.html

    Btw, MacOSX comes with a nice "Visual Studio" incorporated. Is called XCode and comes with GCC 4 ( C, C++, Java and Objective C ), an integrated debugger and the Interface Builder to make nice Windows-onClick-button applications. More info about XCode at
    http://www.apple.com/uk/macosx/features/xcode/

    and about the Interface Builder:

    http://en.wikipedia.org/wiki/Interface_Builder

    Personally I would just use GLX in the same manner than linux . Just press over that "X11" icon in your MacOSX /Applications tools folder.

    Hope it helps ( you own me a nice Rad2900 and the source code of your new Global Illumination DX10 app in http://www.hardspell.com/english/doc...sp?news_id=479

    I recognize those FPS numbers Mr.Humus!

    )

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Dec 2001
    Location
    Wellington, New Zealand
    Posts
    548

    Re: Sample GL code for Mac that doesn't use glut

    X11 is not installed by default, there have been small issues with OpenGL in it in the past, and it's very un-Mac-like. I definitely wouldn't advise touching it with a barge pole.

    Cocoa is definitely the easiest route. There's lots of code all over the place; a personal plug would be http://onesadcookie.com/book

    Mac ports of your stuff would be much appreciated

  4. #4
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Sample GL code for Mac that doesn't use glut

    Originally posted by santyhamer:
    Basically you have five options:
    Well, it'll have to work with my existing code, so it's C++, so that excluded 1 and 5, and I don't want to use glut so that option is out too. I've considered the X11 option too, but since that's not installed by default, I think AGL is what I need. Thanks for the links, they are very useful.

    Originally posted by santyhamer:
    I recognize those FPS numbers Mr.Humus!

    Guilty as charged, but I can't comment on it at this time.

  5. #5
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Sample GL code for Mac that doesn't use glut

    Originally posted by OneSadCookie:
    http://onesadcookie.com/book
    Thanks! Your SimpleAGL sample looks exactly like what I need. I don't have the system yet, so I haven't tried it yet, but it looks like I good starting point.

    Originally posted by OneSadCookie:
    Mac ports of your stuff would be much appreciated
    I hope to make the framework compatible so that all future demos would compile fine on Mac just automagically, like most things do for Linux. I just make a quick test once I'm done and usually I don't need to make any changes for Linux. I'm not keeping the system though, so chances are not all demos will work all the time since I can't test, but hopefully it'll work out fine most of the time.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Dec 2001
    Location
    Wellington, New Zealand
    Posts
    548

    Re: Sample GL code for Mac that doesn't use glut

    I'd really recommend Cocoa over AGL. As has been said, you can freely mix ObjC, C, and C++ depending on your precise needs.

    AGL is icky, ancient, and relies on QuickDraw which is deprecated in Tiger, and isn't even present for 64-bit code in Leopard.

  7. #7
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Sample GL code for Mac that doesn't use glut

    GameEngineII running on the Mac:
    http://www.humus.ca/temp/GameEngineII_MacOSX.jpg


    Got everything working, except one minor detail. I can't seem to find any way to catch the Command-Q event. RunApplicationEventLoop() quits, but that's not enough given the way my framework work, it'll just restart and create a new window since the application didn't set done=true.

  8. #8
    Advanced Member Frequent Contributor
    Join Date
    Dec 2001
    Location
    Wellington, New Zealand
    Posts
    548

    Re: Sample GL code for Mac that doesn't use glut

    According to the docs, you should "install an AppleEvent handler for the kAEQuitApplication event handler if it needs to check for unsaved documents or do other cleanup before quitting".

    No idea how to do that, sorry :|

  9. #9
    Senior Member OpenGL Guru Humus's Avatar
    Join Date
    Mar 2000
    Location
    Stockholm, Sweden
    Posts
    2,444

    Re: Sample GL code for Mac that doesn't use glut

    Thanks, got that working too. So much easier when I know exactly what to google for. Now all issues should be ironed out.

    I've uploaded the updated framework to my website if anyone's interested in trying to compile any of my demos. You'll have to create your own xcode projects though since I've already packed down the machine in the box and won't be able to create any project files for Mac in the future either since I won't have a machine anymore. But it should be quick enough to just include the neccesary framework files (just look in the Makefile for Linux as a reference if neccesary, except you use MacBase.cpp instead of LinuxBase.cpp). And you have to ensure the app runs from the project path rather than "build/debug" or whatever it's by default. Actually, that's one issue remaining. If anyone knows a way to find the path of the current .exe on the Mac that would be very useful.

    Now I just have to hope my Mac code won't break anytime soon because it would be hard to fix.

  10. #10
    Advanced Member Frequent Contributor
    Join Date
    Dec 2001
    Location
    Wellington, New Zealand
    Posts
    548

    Re: Sample GL code for Mac that doesn't use glut

    Now that it's going, it'll be much easier for someone else to maintain... if you can find a willing victim

    CFBundleCopyExecutableURL will find the executable URL (but you probably want CFBundleCopyResourcesDirectoryURL or CFBundleCopyBundleURL instead).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •