如何在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发布于 2012-08-13 22:55:36
苹果公司有一个名为GLEssentials的示例代码项目,它确切地展示了如何做到这一点(请注意,它是Mac和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.2API中删除的任何OpenGL应用程序接口调用,您的应用程序将崩溃。这是3.2规范的PDF document,因此您可以看到这些更改。
https://stackoverflow.com/questions/11602406
复制相似问题