1

我正在使用 OpenCL/OpenGL 互操作,并且已经能够让它在 OSX 上成功运行:

props[0] = CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE;
props[1] = (cl_context_properties) CGLGetShareGroup( CGLGetCurrentContext() );

但是,当使用 X 通讯员时:

props[0] = CL_GL_CONTEXT_KHR;
props[1] = (cl_context_properties) glXGetCurrentContext();
props[2] = CL_GLX_DISPLAY_KHR;
props[3] = (cl_context_properties) glXGetCurrentDisplay();
props[4] = CL_CONTEXT_PLATFORM;
props[5] = (cl_context_properties) pID;

OpenGL初始化代码:

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

screenWidth  = glutGet(GLUT_SCREEN_WIDTH);
screenHeight = glutGet(GLUT_SCREEN_HEIGHT);

glutInitWindowPosition( (screenWidth - width)/2 , (screenHeight - height)/2 );
glutInitWindowSize(width, height);
glutCreateWindow(appName.c_str());

glClearColor (0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glEnable(GL_COLOR_MATERIAL);

glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glEnable (GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glutDisplayFunc(render_s);
glutIdleFunc(render_s);
glutReshapeFunc(resize_s);
glutKeyboardFunc(keyPress_s);
glutKeyboardUpFunc(keyRelease_s);
glutMouseFunc(mousePress_s);
glutMotionFunc(mouseDrag_s);
glutPassiveMotionFunc(mouseMove_s);

在获取上下文之前调用初始化代码。

glXGetCurrentContext() 没有段错误,但 glXGetCurrentDisplay() 有。

排除互操作,为什么即使在调用 glutInit() 之后 glXGetCurrentDisplay() 也会出现段错误

PS有没有办法在OpenGL下明确选择平台/设备?

4

2 回答 2

5

即使在调用 glutInit() 之后也会出现故障

glutInit不会创建 OpenGL 上下文,因此 glXGetCurrentDisplay 将失败。您需要调用glutCreateWindow以实际创建上下文。

于 2013-01-11T13:54:19.897 回答
1

我只是面临同样的问题。我发现你需要初始化 glx 扩展。我正在为此使用 glew,因此我需要glewInit()在创建上下文后调用才能glXGetCurrentDisplay()正常工作。

检查你的标题。如果包括在内,则GL/glxew.h需要以某种方式初始化函数指针。如果包含GL/glx.h它应该可以正常工作。

于 2013-11-12T14:17:22.230 回答