2012-08-28 69 views
1

我无法获得NSOpenGLContext的工作。 我有一个静态对象(3D引擎)办理所有OpenGL的东西,资源,维也纳组织等。NSOpenglContext资源,呈现错误

对于可可版本,我创建了一个NSOpenGLContext这样的:

- (BOOL) CreateContext 
{ 
    [NSOpenGLContext clearCurrentContext]; 

    NSOpenGLPixelFormatAttribute attributes [] = 
    { 
    NSOpenGLPFAWindow, 
    NSOpenGLPFADoubleBuffer, 
    NSOpenGLPFAAccelerated,   // If present, this attribute indicates that only hardware-accelerated renderers are considered. 
    NSOpenGLPFAPixelBuffer,   // If present, this attribute indicates that rendering to a pixel buffer is enabled. 
    NSOpenGLPFAColorSize, 32, 
    NSOpenGLPFADepthSize, 24, 
    NSOpenGLPFAStencilSize, 8, 
    (NSOpenGLPixelFormatAttribute)nil 
    }; 

    NSOpenGLPixelFormat* pixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attributes]; 
    NSOpenGLContext* pContext = [[NSOpenGLContext alloc] initWithFormat: pixelFormat shareContext:nil]; 

    if (pContext) 
    { 
     [pContext makeCurrentContext]; 
     m_pOGLContext = pContext; 

     // Vertical Sync 
     GLint vblSynch = 0; // disable vsync 
     [pContext setValues:&vblSynch forParameter:NSOpenGLCPSwapInterval]; 

     glFrontFace(GL_CW); 

     // Set the clear Color 
     glClearColor(0, 0, 0, 0); 

     [pixelFormat release]; 
     return true; 
    } 

    [pixelFormat release]; 

    return false; 
} 

发动机初始化之后,我创建了一个NSView。 所述的NSView创建之后,在prepareOpenGL FUNC,我刚NSOpenGLContext构件从发动机设置为当前NSOpenGLContext:

- (void) prepareOpenGL 
{ 
    m_pOGLContext = [NSOpenGLContext currentContext]; 
    return; 
} 

然后,在一个NSView的功能lockFocus我设置用于上下文中的视图:

- (void)lockFocus 
{ 
    [super lockFocus]; 

    if ([m_pOGLContext view] != self) 
    { 
     [m_pOGLContext setView:self]; 
    } 

    [m_pOGLContext makeCurrentContext]; 
} 

现在,当绘图时我无法获取绘制资源,我只是有很多缓冲器工件。

我试图用共享选项为NSView创建第二个上下文,但我有相同的结果。

+0

你刷新使用“MAC方式”缓冲区?我不认为glFlush()在我之前为我工作,我不得不使用NSOpenGLContext的flushBuffer。 – TheAmateurProgrammer

+0

嗨,glflush正在为我工​​作,事实上我第一次使用静态上下文,没关系。问题发生在我销毁视图的时候,创建另一个再次使用静态上下文的视图。 – Ziggy

回答

0

不知道,我是一个新手太多,但我认为,格式是错误的,它应该是:

NSOpenGLPixelFormatAttribute attributes [] = 
{ 
NSOpenGLPFAWindow, 
NSOpenGLPFADoubleBuffer, 
NSOpenGLPFAAccelerated,   // If present, this attribute indicates that only hardware-accelerated renderers are considered. 
NSOpenGLPFAPixelBuffer,   // If present, this attribute indicates that rendering to a pixel buffer is enabled. 
NSOpenGLPFAColorSize, 
NSOpenGLPFADepthSize, 
NSOpenGLPFAStencilSize, 
32,24,8, 
(NSOpenGLPixelFormatAttribute)nil 
};