首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSOpenGLView不会清除

NSOpenGLView不会清除
EN

Stack Overflow用户
提问于 2013-07-23 03:38:51
回答 2查看 724关注 0票数 1

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

代码语言:javascript
复制
-(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);

 }

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-24 05:15:21

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

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

票数 1
EN

Stack Overflow用户

发布于 2018-07-13 15:33:22

您应该使用CGLFlushDrawable()。如blow:

代码语言:javascript
复制
CGLFlushDrawable([[self openGLContext] CGLContextObj]);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17795984

复制
相关文章

相似问题

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