我正在尝试在我的Mac上编译OpenGL + OpenCL代码并经过大量努力设法安装依赖项并了解如何链接它们(GLUI,GLUT,OpenCL等)。
大部分错误已被删除,但仍有3个错误仍然存在,如下所示:
pranjal:~/parallel-prog$ g++-4.9 mittalp.cpp -fopenmp -framework OpenCL -framework OpenGL -framework GLUI -framework GLUT -w
mittalp.cpp: In function 'void InitCL()':
mittalp.cpp:465:69: error: 'wglGetCurrentContext' was not declared in this scope
CL_GL_CONTEXT_KHR, (cl_context_properties) wglGetCurrentContext( ),
^
mittalp.cpp:466:62: error: 'wglGetCurrentDC' was not declared in this scope
CL_WGL_HDC_KHR, (cl_context_properties) wglGetCurrentDC( ),
^
mittalp.cpp: In function 'void InitGlui()':
mittalp.cpp:619:37: error: 'FALSE' was not declared in this scope
Glui->add_column_to_panel( panel, FALSE );
^
我尝试了所有我知道的编译器标志,并且无法编译。该代码在朋友的机器上在Windows上运行良好,但它在我的Mac OS X上不起作用。我怀疑错误是因为错误中列出的3个函数是特定于窗口的。由于我是OpenGL编程的新手,我对OS X等效函数知之甚少,或者我的Mac上需要哪些库才能使这些特定于Windows的函数有效。
我添加了C ++代码here以供参考:
答案 0 :(得分:4)
这是我用来初始化OpenCL上下文属性以在Windows,OS X和Linux上启用OpenGL互操作性的代码:
#if defined(_WIN32)
// Windows
cl_context_properties properties[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)wglGetCurrentContext(),
CL_WGL_HDC_KHR, (cl_context_properties)wglGetCurrentDC(),
CL_CONTEXT_PLATFORM, (cl_context_properties)platform,
0
};
#elif defined(__APPLE__)
// OS X
CGLContextObj kCGLContext = CGLGetCurrentContext();
CGLShareGroupObj kCGLShareGroup = CGLGetShareGroup(kCGLContext);
cl_context_properties properties[] = {
CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
(cl_context_properties) kCGLShareGroup,
0
};
#else
// Linux
cl_context_properties properties[] = {
CL_GL_CONTEXT_KHR, (cl_context_properties)glXGetCurrentContext(),
CL_GLX_DISPLAY_KHR, (cl_context_properties)glXGetCurrentDisplay(),
CL_CONTEXT_PLATFORM, (cl_context_properties)platform,
0
};
#endif