gpt4 book ai didi

macos - NSOpenGLView 不会清除

转载 作者:行者123 更新时间:2023-12-03 17:12:33 28 4
gpt4 key购买 nike

我正在使用 Cocoa 窗口和 NSOpenGLView 尝试 OpenGL 3.2。但是我无法让 NSOpenGLView 绘制红色。我只得到一个白色的窗口。这是我的代码(在 NSOpenGLView 的子类中):

-(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];


}


- (id)initWithFrame:(NSRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}

return self;
}

- (void)drawRect:(NSRect)dirtyRect
{

glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);

}

代码应该简单地将 View 清除为红色。没有错误或警告——只有一个白色窗口。

最佳答案

在调用 glClear() 后,我需要使用 glSwapAPPLE() 交换缓冲区

我在某处读到 NSOpenGLViews 不需要交换,因为它是自动完成的。根据我的经验,我可以说这是完全不真实的。

关于macos - NSOpenGLView 不会清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17795984/

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