如何在C ++中编写Cocoa OpenGL应用程序? [英] How to write a Cocoa OpenGL app in C++?

查看:217
本文介绍了如何在C ++中编写Cocoa OpenGL应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在编写一个应用程序,需要使用OpenGL,在Mac上,在C + +。

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

有没有反正我可以得到Cocoa只给我一个OpenGL上下文,让我在C ++中做我的工作? (我想我的应用程序在Mac OS X和iPHone上运行;但所有的GUI都在OpenGL中,我只需要一个OpenGL上下文)。

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 iPHone; but all the GUI is in OpenGL, I just need a OpenGL context).

谢谢! p>

Thanks!

推荐答案

你不能逃离最小量的objective-C代码。但是,如果将目标C文件重命名为.mm文件,目标C代码将能够调用c ++类方法。这意味着你可以挂钩-drawRect(和其他相关的NSOpenGLView消息)到你的c ++ OpenGL实现。 NSOpenGLView有一个-makeCurrent方法,你可以在drawRect之外调用,以确保正确的OpenGL上下文是活动的。

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.

然后你的c ++代码可以根据需要调用gl函数。

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

这篇关于如何在C ++中编写Cocoa OpenGL应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆