简体   繁体   English

有没有一种简单的方法可以在Mac OS X中使用C ++打开一个(或多个)opengl窗口?

[英]Is there a simple way for opening one (or many) opengl window in mac OS X with C++?

Yes, I hate Objective-c, plus my project will be portable, so I'd like to code as much of it in C++ as possible, ideally 100%. 是的,我讨厌Objective-c,而且我的项目是可移植的,所以我想用C ++编写尽可能多的代码,理想的是100%。
So I have a regular C++ project made with Xcode, and want to open some OpenGL windows. 所以我有一个使用Xcode制作的常规C ++项目,并且想要打开一些OpenGL窗口。

edit: Damn, Glut takes over the app's control with glutMainLoop() and I'll like to have more control over the loop. 编辑:该死的,Glut用glutMainLoop()接管应用程序的控件,我想对循环有更多的控制权。
Will try freeglut, although I can't find OSX binaries, and I always have such bad luck trying to compile someone else's code. 尝试freeglut,虽然我找不到OSX二进制文件,但我总是试图编译其他人的代码。

Update: 更新:
I tried yet again to link to SDL 1.3 and this time I could get it to work! 我再次尝试链接到SDL 1.3,这次我可以让它工作! yoo-hoo! 俞灏!
I always wanted to work with SDL, but using more than one window was mandatory, and that's a feature of version 1.3 which is under development and I never could get it working. 我一直想使用SDL,但是必须使用多个窗口,这是版本1.3的一个功能,正在开发中,我永远无法让它工作。
As it is portable to a zillion OSes, and handles 2D graphics as well as OpenGL I'm going with it. 由于它可以移植到数以万计的操作系统,并且处理2D图形以及OpenGL,我将继续使用它。 Thanks to all! 谢谢大家!

If you don't want to use objective-c you're going to have to use either the deprecated carbon libraries, X11, or another library like GLUT to create the window. 如果您不想使用objective-c,则必须使用已弃用的碳库X11或其他库(如GLUT)来创建窗口。 If portability is a concern either go the GLUT route, or you'll need to write your own window management code for each platform you want to support. 如果可移植性是一个问题,要么去GLUT路线,要么你需要为你想要支持的每个平台编写自己的窗口管理代码。

If you don't go the GLUT route you will need to write window management code fore each operating system so I strongly suggest you bite the bullet and write the window management in objective-c++. 如果你不去GLUT路线,你需要在每个操作系统之前编写窗口管理代码,所以我强烈建议你咬紧牙关并用objective-c ++编写窗口管理。 The only thing you really need to know is that a pointer is always a pointer no matter which language it is in, so just store objective-c ids as void* and cast them back to ids, it actually works out pretty easy. 你真正需要知道的唯一事情是指针总是一个指针,无论它处于哪种语言,所以只需将objective-c id存储为void *并将它们转换回id,它实际上很容易实现。

我猜NeHe教程可以提供帮助;

GLUT works fine for your stated purpose, although you will probably wish for a nice C++ wrapper for it. GLUT可以很好地满足你的目的,虽然你可能希望有一个很好的C ++包装器。 I ended up hacking my own, and although GLUT isn't friendly to wrapping, it was doable. 我最终破解了自己,虽然GLUT对包装不友好,但它是可行的。

EDIT: Since you have a problem with glutMainLoop(), you may be trying to do more than GLUT was designed to do -- it is mainly intended for hacks, one-off projects and opengl demos. 编辑:由于你有glutMainLoop()的问题,你可能会尝试做更多的GLUT设计 - 它主要用于黑客,一次性项目和opengl演示。 And freeglut doesn't compile OOB on the mac, at least that was my experience. 并且freeglut不会在mac上编译OOB,至少这是我的经验。

For a portable, fuller featured app, Qt may be the way to go for you. 对于便携式,功能更全面的应用程序,Qt可能是您的最佳选择。 Otherwise, design your C++ for portability and use a thin GUI layer on each platform. 否则,设计C ++以实现可移植性,并在每个平台上使用瘦GUI层。 If getting something running on each platform is most important, go for the former. 如果在每个平台上运行某些东西是最重要的,请选择前者。 If the best user experience on each platform is most important, go for the latter. 如果每个平台上最佳用户体验最重要,请选择后者。 You may find that "thin" is not the most descriptive term for what is involved. 您可能会发现“瘦”并不是所涉及内容的最具描述性的术语。

I found this demo to be useful for getting a simple Cocoa/OpenGL window working, even though the code has a number of ridiculous bugs: http://developer.apple.com/library/mac/#samplecode/CocoaGL/Introduction/Intro.html 我发现这个演示对于使一个简单的Cocoa / OpenGL窗口工作非常有用,即使代码中有许多荒谬的错误: http//developer.apple.com/library/mac/#samplecode/CocoaGL/Introduction/Intro html的

This question has been asked over 3 years ago, yet remain quite fresh. 这个问题已在3年前提出过,但仍然很新鲜。 I just recently went through similar exercise for planning school curriculum, and trying to figure out what's the best portable library to work with on Mac/Windows/Linux/mobile with OpenGL projects. 我最近刚刚进行了类似的计划学校课程练习,并试图找出在Mac / Windows / Linux /移动设备上使用OpenGL项目的最佳便携式库。 Perhaps my notes will help someone make a decision. 也许我的笔记会帮助某人做出决定。 I only mention the main options that I've considered. 我只提到了我考虑过的主要选项。

Higher level APIs , for window management plus additional goodies, like sprites, fonts, sounds, event handling, etc: 更高级别的API ,用于窗口管理以及其他好东西,如精灵,字体,声音,事件处理等:

  • SFML and github repo : nice&tidy, C++, object oriented library that integrates with OpenGL natively. SFMLgithub repo :漂亮而整洁,C ++,面向对象的库,本身与OpenGL集成。 Portability for managing windows and OpenGL 3.3 contexts out of the box on MacOS, Win and Linux. 在MacOS,Win和Linux上开箱即用的管理Windows和OpenGL 3.3上下文的可移植性。 Mobile support provided in the 2.2 branch (github). 2.2分支(github)中提供的移动支持。
  • SDL2 : all major platforms, including mobile, supported. SDL2 :支持所有主要平台,包括移动平台。 The OpenGL context needs to be manually managed somewhat, so use of GLEW for example comes really handy (see below). OpenGL上下文需要在某种程度上手动管理,因此使用GLEW非常方便(见下文)。 A bit lower level than SFML. 比SFML略低一点。

Lower level APIs , mostly for window and OpenGL context management: 较低级别的API ,主要用于窗口和OpenGL上下文管理:

  • GLWF : This is pretty much a GLUT replacement for modern OpenGL. GLWF :这几乎是现代OpenGL的GLUT替代品。 Rather low level, but portable across: Win, OSX, Lin. 相当低级别,但可移植:Win,OSX,Lin。 In active development. 积极发展。
  • GLEW : I only mention it for completness. GLEW :我只提到它的完整性。 It doesn't manage windows, but helps managing OpenGL contexts and you might use it together with GLWF or SDL for example. 它不管理窗口,但有助于管理OpenGL上下文,您可以将它与GLWF或SDL一起使用。

Others: 其他:

  • Freeglut : Open source continuation of GLUT. Freeglut :GLUT的开源继续。 Suitable for small demo projects. 适用于小型演示项目。 I have not used it myself, but seen good docs and demo code. 我自己没有使用它,但看到了很好的文档和演示代码。 In active development. 积极发展。
  • GLUT: old one, discontinued. GLUT:旧的,停产了。 Legacy demos and code around the net. 网络上的遗留演示和代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM