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

前端 未结 3 677
执笔经年
执笔经年 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

提交回复
热议问题