gpt4 book ai didi

objective-c - 带 NSOpenGLView 的 OpenGL 3.2

转载 作者:太空狗 更新时间:2023-10-30 03:41:19 25 4
gpt4 key购买 nike

如何在 NSOpenGLView 的自定义实现中创建核心配置文件?我应该覆盖哪个方法以及应该在其中放置什么代码?

到目前为止我有这段代码:

// Header File
#import <Cocoa/Cocoa.h>

@interface TCUOpenGLView : NSOpenGLView

@end

// Source File
#import "TCUOpenGLView.h"
#import <OpenGL/gl.h>

@implementation TCUOpenGLView

- (void)drawRect:(NSRect)dirtyRect {
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

@end

最佳答案

Apple 有一个名为 GLEssentials 的示例代码项目它准确地显示了如何执行此操作(请注意,这是一个 Mac OS X 和 iOS 示例代码项目)。

本质上,您需要子类化 NSOpenGLView(示例代码中的 NSGLView 类)并使用以下方法实现 awakeFromNib 方法:

- (void) awakeFromNib
{
NSOpenGLPixelFormatAttribute attrs[] =
{
NSOpenGLPFADoubleBuffer,
NSOpenGLPFADepthSize, 24,
// Must specify the 3.2 Core Profile to use OpenGL 3.2
NSOpenGLPFAOpenGLProfile,
NSOpenGLProfileVersion3_2Core,
0
};

NSOpenGLPixelFormat *pf = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attrs] autorelease];

if (!pf)
{
NSLog(@"No OpenGL pixel format");
}

NSOpenGLContext* context = [[[NSOpenGLContext alloc] initWithFormat:pf shareContext:nil] autorelease];

[self setPixelFormat:pf];

[self setOpenGLContext:context];
}

另请记住,如果您使用任何已从 3.2 API 中删除的 OpenGL API 调用,您的应用程序将会崩溃。这是一个 PDF document 3.2 规范,以便您可以看到更改。

关于objective-c - 带 NSOpenGLView 的 OpenGL 3.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11602406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com