OpenGL with Cocoa: No matching function call when trying to call CGLLockContext([[self openGLContext] CGLContextObj]);

StackOverflow https://stackoverflow.com/questions/21073276

Question

I am learning OpenGL. To get an OpenGL context setup I was following the GlEssentials example from Apple. The GlContext is there locked in the draw method as follows:

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

When I tried to call CGLLockContext with exactly the same arguments as above in my view class I the following error:

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 *')

Quickly inserting a typecast fixed the issue:

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

Question is why? In Apples example it works fine without this typecast.

Was it helpful?

Solution

Two thoughts:

1) Are you doing this inside a C++ or ObjC++ file? That whole “candidate function” thing sounds like C++ to me, but I don’t really know C++.

2) Are your compiler flags (especially warnings and errors) the same in your project files as they are in Apple’s sample project. (I took a quick look at Xcode 5’s compiler settings and nothing jumped out at me.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top