如果这个问题是微不足道的,或者nonsense...this是我正在开发的第一个应用程序之一,我提前道歉。(不幸的是)我不是一个开发者。
我有一个包含自定义视图的NSWindow,它是NSOpenGLView的一个子类。
因为NSWindow和NSOpenGLView是通过接口生成器创建的,所以我不需要init NSOpenGLContext或NSOpenGLPixelFormat。
我最近切换到了OS,现在我想利用新的OpenGL 3.2。
从苹果的文档中我发现,要启用OpenGL 3.2,我只需要编写如下代码:
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:方法:
-(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我不能解决这个问题。
我该怎么做呢?
发布于 2011-10-09 16:43:59
听起来你的代码是基于OpenGL 2.1的。Lion中的OpenGL 3.2只支持核心配置文件(没有兼容性配置文件),这意味着所有固定功能的流水线东西(例如glBegin/End,glVertex,glPushMatrix,glMultMatrix)都已经消失了。
你必须经常更新你的代码。如果你已经使用了VBO,工作量会更少。
发布于 2011-09-23 20:31:05
NSOpenGLView有一个setOpenGLContext方法。以这种方式将您的3.2上下文传递给视图,然后在NSOpenGLContext上调用setView。
我还没有测试过它,但是它应该可以工作,尽管我刚刚做了我自己的OpenGL视图。
发布于 2012-01-10 11:11:30
使用setPixelFormat…在我的子类中,awakeFromNib可以为我工作,尽管它让我感到不舒服,因为文档中没有任何内容承诺应该这样做。
此覆盖是界面生成器中的任何设置。我找不到一种非弃用的方法来检查像素格式,以便将我需要的像素格式添加到在Interface Builder中选择的像素格式中。
希望IB人员会将其添加到那里,或者更好的是,NSOpenGLView类将为子类提供一种机制,以便在
https://stackoverflow.com/questions/7472622
复制相似问题