Reputation: 414
I'm working with OpenCL/OpenGL interop and have been able to get it successfully working on OSX:
props[0] = CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE;
props[1] = (cl_context_properties) CGLGetShareGroup( CGLGetCurrentContext() );
However, when using the X correspondent:
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 init code:
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);
The init code is called before getting the context.
glXGetCurrentContext() didn't segfault, but glXGetCurrentDisplay() did.
Excluding the interop, why would glXGetCurrentDisplay() seg fault even after calling glutInit()
P.S. Is there a way to explicitly choose the platform/device under OpenGL?
Upvotes: 1
Views: 865
Reputation: 1271
I just face the same problem. What I found is that you need to initialize the glx extensions. I'm using glew for this one so I need to call glewInit()
after the context was created in order to glXGetCurrentDisplay()
to work properly.
Check your headers. If you are including GL/glxew.h
you need to initialize the function pointers in some way. If you include GL/glx.h
it should work fine.
Upvotes: 1
Reputation: 162164
fault even after calling glutInit()
glutInit
doesn't create an OpenGL context, so glXGetCurrentDisplay will fail. You need to call glutCreateWindow
to actually create a context.
Upvotes: 5