开发者

How to write a Cocoa OpenGL app in C++?

开发者 https://www.devze.com 2022-12-17 18:55 出处:网络
I\'m writing an application that needs to use OpenGL, on the Mac, in C++. Is there anyway I can get Cocoa to just give me an OpenGL context and let me do my work in C++? (I want my app to run on both

I'm writing an application that needs to use OpenGL, on the Mac, in C++.

Is there anyway I can get Cocoa to just give me an OpenGL context and let me do my work in C++? (I want my app to run on both Mac OS X and iPHo开发者_如何学JAVAne; but all the GUI is in OpenGL, I just need a OpenGL context).

Thanks!


You cannot escape a minimal amount of objective-C code. However, if you rename the objective C files to .mm files, the objective C code will be able to call c++ class methods. This means you can hook the -drawRect (and other relevent NSOpenGLView messages) to your c++ OpenGL implementation. The NSOpenGLView has a -makeCurrent method that you can call outside of drawRect to ensure that the correct OpenGL context is active.

Your c++ code can then simply call gl functions as needed.


Look into NSOpenGLView. In drawRect: in your subclass, you can access the view's context and call your OpenGL code.

0

精彩评论

暂无评论...
验证码 换一张
取 消