How can I 'break away' from Cocoa and develop Mac OpenGL applications in C/C++?

前端 未结 3 678
执笔经年
执笔经年 2021-02-09 15:23

I am looking to get started with some 3D programming in C or C++. The problem I have is that it seems like the only tutorials I can find for Mac OS use objective C and Cocoa fra

相关标签:
3条回答
  • 2021-02-09 15:42

    Some portion of Objective-C is inevitable if you want to use the latest benefits of the OSX/Cocoa. The easiest way to port an existing application to MacOS would be the following:

    1. Write the "bare bones" nibless application in Objective-C. It would only be a single AppDelegate class and a little setup in the main() function
    2. Add the custom NSGLView descendant in your window which you create in the AppDelegate's didFinishLaunching event handler
    3. Setup the CVDisplayLink and rendering callback in the NSGLView initialization
    4. Use your existing OpenGL rendering code in the CVDisplayLink's callback

    Now for the interesting part: where to get all of this ?

    Surprisingly, a good nibless application sample is the UI for OSX's port of QEMU (yes, the emulator). Also the Apple's official GLEssenstialPractices demo shows all the information you need to set up OpenGL rendering pipeline. All the rest is up to you.

    The detailed and modern introduction to system-level OSX programming can be found in the "Advanced Mac OS X Programming" book by Mark Dalrymple. It explains many things and after reading all of this I've understood most of the design decisions in the OS (it really makes you accept all the "non-standard" things if you think from the performance viewpoint).

    To get through the "nibless" programming I would recommend you to read the blog posts like this one http://blog.kleymeyer.com/2008/05/creating-cocoa-applications-programatically-ie-nib-less/ The google search helps a lot.

    The same tricks apply to the CocoaTouch/iOS and there are a lot of questions answered on SO, like this one Cocoa touch/Xcode - generating NIB-less graphics context

    0 讨论(0)
  • 2021-02-09 15:51

    If you want to create cross-platform applications you could create a project with the Command Line Tool template. Next, import the OpenGL and GLUT framework. This will get you a "blank" C++ project with the required OpenGL and GLUT headers.

    Lighthouse 3D gives you some tips about portability and how to initiate your first project. http://www.lighthouse3d.com/tutorials/glut-tutorial/initialization/

    0 讨论(0)
  • 2021-02-09 16:03

    I have created a software layer (named cocoglut) that allows the translatation of basic or essential GLUT calls to COCOA. This library allows creating/destroying windows and register callbacks from a C/C++ application, just by using GLUT calls, without the need for nib files or for XCode project files (and can be compiled from the command line). This option uses full retina display resolution. The source is on GitHub.

    0 讨论(0)
提交回复
热议问题