我正在学习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/