我用的OpenCL/OpenGL的互操作工作,並已經能夠成功地得到它的工作在OSX:glXGetCurrentDisplay()分段錯誤(Linux)的
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()賽格故障有沒有辦法在OpenGL下明確選擇平臺/設備?
關於你的PS:OpenGL是完全平臺不可知的。它依賴於系統特定的API來爲其創建上下文。在Windows上,這是* WGL *在X11上是* GLX *,在MacOS X上是* CGL *。 – datenwolf
對不起,遲到了,我去了另一個國家哈哈。 謝謝,這有助於很多^^ – Yuuta