jennal
3rd December 2014, 12:00
I am new in qt, and I am trying to make a toolkit for faster game development. My target platform is MacOSX and Windows. I am working on a game engine called cocos2d-x, which used glfw as desktop opengl window. glfw uses NSGL as opengl context in MacOSX and WGL in windows.
Qt 5.4 (http://qt-project.org/wiki/New-Features-in-Qt-5.4) introduced a new class called QOpenGLContext (http://doc-snapshot.qt-project.org/qt5-5.4/qopenglcontext.html) to take place of QGLContext. And QOpenGLContext has a new method setNativeHandle (http://doc-snapshot.qt-project.org/qt5-5.4/qopenglcontext.html#setNativeHandle) which official sai QOpenGLContext is now able to adopt existing native contexts (EGL, GLX, …). This allows interop between Qt and other frameworks, like game engines.
But I tried some ways and all failed.
I try to create a new QOpenGLContext and call setNativeHandle, and set it to setShareContext (http://doc-snapshot.qt-project.org/qt5-5.4/qopenglcontext.html#setShareContext). Then I create a new QOpenGLWidget (http://doc-snapshot.qt-project.org/qt5-5.4/qopenglwidget.html) and hoping it will use the shareContext, but it is not.
I start with a new QOpenGLWidget, then get its context, and call context's setNativeHandle, but it occur an error.
Now I have 2 ideas, but don't know how to approach
create a QOpenGLContext then adopt glfw's gl context to it, and show it to screen.
create a QOpenGLWidget and change its gl context to glfw's gl context.
Someone knows how to approach this? Or my ideas are totally wrong? Please tell me.
Thanks.
Qt 5.4 (http://qt-project.org/wiki/New-Features-in-Qt-5.4) introduced a new class called QOpenGLContext (http://doc-snapshot.qt-project.org/qt5-5.4/qopenglcontext.html) to take place of QGLContext. And QOpenGLContext has a new method setNativeHandle (http://doc-snapshot.qt-project.org/qt5-5.4/qopenglcontext.html#setNativeHandle) which official sai QOpenGLContext is now able to adopt existing native contexts (EGL, GLX, …). This allows interop between Qt and other frameworks, like game engines.
But I tried some ways and all failed.
I try to create a new QOpenGLContext and call setNativeHandle, and set it to setShareContext (http://doc-snapshot.qt-project.org/qt5-5.4/qopenglcontext.html#setShareContext). Then I create a new QOpenGLWidget (http://doc-snapshot.qt-project.org/qt5-5.4/qopenglwidget.html) and hoping it will use the shareContext, but it is not.
I start with a new QOpenGLWidget, then get its context, and call context's setNativeHandle, but it occur an error.
Now I have 2 ideas, but don't know how to approach
create a QOpenGLContext then adopt glfw's gl context to it, and show it to screen.
create a QOpenGLWidget and change its gl context to glfw's gl context.
Someone knows how to approach this? Or my ideas are totally wrong? Please tell me.
Thanks.