首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >采用OpenGL 3.2核心的NSOpenGLView

采用OpenGL 3.2核心的NSOpenGLView
EN

Stack Overflow用户
提问于 2011-09-19 22:36:18
回答 3查看 4.7K关注 0票数 3

如果这个问题是微不足道的,或者nonsense...this是我正在开发的第一个应用程序之一,我提前道歉。(不幸的是)我不是一个开发者。

我有一个包含自定义视图的NSWindow,它是NSOpenGLView的一个子类。

因为NSWindowNSOpenGLView是通过接口生成器创建的,所以我不需要init NSOpenGLContextNSOpenGLPixelFormat

我最近切换到了OS,现在我想利用新的OpenGL 3.2。

从苹果的文档中我发现,要启用OpenGL 3.2,我只需要编写如下代码:

代码语言:javascript
复制
NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
    {
        NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
        0
    };

    NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease];
    NSOpenGLContext* openGLContext = [[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil] autorelease];

在初始化NSOpenGLContext之前。

这很简单(即使对我来说也是如此),但由于我从不init NSOpenGLContext,我如何在我的应用程序中实现这一点

由于NSOpenGLView是从接口生成器创建的,因此不会调用-initWithFormat:shareContext:方法。

因此,我尝试用下面这样的代码覆盖-initWithCoder:方法:

代码语言:javascript
复制
-(id)initWithCoder:(NSCoder *)aDecoder
{
 NSOpenGLPixelFormatAttribute pixelFormatAttributes[] =
    {
        NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core,
        0
    };

    NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:pixelFormatAttributes] autorelease];
    NSOpenGLContext* openGLContext = [[[NSOpenGLContext alloc] initWithFormat:pixelFormat shareContext:nil] autorelease];
    [super initWithCoder:aDecoder];
    [self setOpenGLContext:openGLContext];
    [openGLContext makeCurrentContext];
}

并且如glGetString(GL_VERSION)所报告的那样,OpenGL 3.2被正确加载,但是创建的上下文不再与视图中绘制的app...nothing交互。

我试了所有我知道的of...but我不能解决这个问题。

我该怎么做呢?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-10-09 16:43:59

听起来你的代码是基于OpenGL 2.1的。Lion中的OpenGL 3.2只支持核心配置文件(没有兼容性配置文件),这意味着所有固定功能的流水线东西(例如glBegin/End,glVertex,glPushMatrix,glMultMatrix)都已经消失了。

你必须经常更新你的代码。如果你已经使用了VBO,工作量会更少。

票数 1
EN

Stack Overflow用户

发布于 2011-09-23 20:31:05

NSOpenGLView有一个setOpenGLContext方法。以这种方式将您的3.2上下文传递给视图,然后在NSOpenGLContext上调用setView。

我还没有测试过它,但是它应该可以工作,尽管我刚刚做了我自己的OpenGL视图。

票数 4
EN

Stack Overflow用户

发布于 2012-01-10 11:11:30

使用setPixelFormat…在我的子类中,awakeFromNib可以为我工作,尽管它让我感到不舒服,因为文档中没有任何内容承诺应该这样做。

此覆盖是界面生成器中的任何设置。我找不到一种非弃用的方法来检查像素格式,以便将我需要的像素格式添加到在Interface Builder中选择的像素格式中。

希望IB人员会将其添加到那里,或者更好的是,NSOpenGLView类将为子类提供一种机制,以便在

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7472622

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档