1

我正在学习 OpenGL。为了获得 OpenGL 上下文设置,我遵循 Apple 的GlEssentials示例。GlContext 被锁定在 draw 方法中,如下所示:

- (void) drawView
{    
    [[self openGLContext] makeCurrentContext];

    // We draw on a secondary thread through the display link
    // When resizing the view, -reshape is called automatically on the main
    // thread. Add a mutex around to avoid the threads accessing the context
    // simultaneously when resizing
    CGLLockContext([[self openGLContext] CGLContextObj]);

    [m_renderer render];

    CGLFlushDrawable([[self openGLContext] CGLContextObj]);
    CGLUnlockContext([[self openGLContext] CGLContextObj]);
}

当我尝试CGLLockContext在视图类中使用与上面完全相同的参数调用时,出现以下错误:

No matching function for call to 'CGLLockContext

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/OpenGL.framework/Headers/OpenGL.h:111:17: Candidate function not viable: cannot convert argument of incomplete type 'void *' to 'CGLContextObj' (aka '_CGLContextObject *')

快速插入类型转换解决了这个问题:

CGLLockContext((CGLContextObj)[[self openGLContext] CGLContextObj]);

问题是为什么?在 Apples 示例中,没有这种类型转换它可以正常工作。

4

1 回答 1

1

两个想法:

1)您是在 C++ 或 ObjC++ 文件中执行此操作吗?整个“候选函数”对我来说听起来像 C++,但我并不真正了解 C++。

2)您的项目文件中的编译器标志(尤其是警告和错误)是否与 Apple 示例项目中的相同。(我快速查看了 Xcode 5 的编译器设置,没有任何反应。)

于 2014-01-12T11:37:35.927 回答