objective-c - OpenGL 与 Cocoa : No matching function call when trying to call CGLLockContext([[self openGLContext] CGLContextObj]);

标签 objective-c cocoa opengl nsopenglview

我正在学习OpenGL。为了获得 OpenGL 上下文设置,我遵循了 GlEssentials来自苹果公司的例子。 GlContext 被锁定在绘制方法中,如下所示:

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

当我尝试在 View 类中使用与上面完全相同的参数调用 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]);

问题是为什么?在苹果的例子中,没有这种类型转换它也能正常工作。

最佳答案

两个想法:

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

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

关于objective-c - OpenGL 与 Cocoa : No matching function call when trying to call CGLLockContext([[self openGLContext] CGLContextObj]);,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21073276/

相关文章:

java - 使用 Java 7 的 Linux 上的立体问题 - 如何在将组件添加到父组件后更改组件的 GC

c++ - 调用 OpenGL 函数时程序崩溃

ios - 更改电池附件类型?

ios - Google 登录在 iOS 中不起作用 - 无效的 GOOGLE_APP_ID 错误

ios - 绘制矩形 :withAttributes dies with "message sent to deallocated instance"

iphone - cocoa touch 显示屏 多种货币

macos - 无法在 Mac 上注册 Apple 推送通知服务

ios - 如何设置容器 View 以交换两个 child

ios - 异步执行但同步写入

c - 如何使用 GLUT 在按键上的纹理/帧缓冲区之间切换?