Results 1 to 6 of 6

Thread: problem with combine Qt 5.4 QOpenGLContext to native opengl context

  1. #1
    Join Date
    Nov 2014
    Posts
    6
    Thanks
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Question problem with combine Qt 5.4 QOpenGLContext to native opengl context

    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 introduced a new class called QOpenGLContext to take place of QGLContext. And QOpenGLContext has a new method 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.

    1. I try to create a new QOpenGLContext and call setNativeHandle, and set it to setShareContext. Then I create a new QOpenGLWidget and hoping it will use the shareContext, but it is not.
    2. 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
    1. create a QOpenGLContext then adopt glfw's gl context to it, and show it to screen.
    2. 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with combine Qt 5.4 QOpenGLContext to native opengl context

    Quote Originally Posted by jennal View Post
    I try to create a new QOpenGLContext and call setNativeHandle, and set it to setShareContext. Then I create a new QOpenGLWidget and hoping it will use the shareContext, but it is not.
    What sense would it make? If you already have a surface to draw on which context you want to adopt, what would creating a new widget (hence another surface to draw on) do? Where would the rendering occur?

    I start with a new QOpenGLWidget, then get its context, and call context's setNativeHandle, but it occur an error.
    Again, in my opinion this doesn't make sense.

    Am I right that you would like your alien game engine render within Qt's window? In that case it is the game engine that should adopt Qt's context, not the other way round. You could probably use a QOpenGLFramebufferObject and bind it with the adopted context, then make your game engine render itself to the FBO and then use that FBO as a texture in Qt.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    jennal (3rd December 2014)

  4. #3
    Join Date
    Nov 2014
    Posts
    6
    Thanks
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: problem with combine Qt 5.4 QOpenGLContext to native opengl context

    Yes, I want to render game engine in Qt's window. And the game engine used glfw as its window. I want to adopt glfw's gl context to QOpenGLContext, or there is some other way to do that?

    Game Engine Team tried to adopt to Qt context, but they failed and give up Qt. And I found new feature from Qt 5.4 may solve this problem with new QOpenGLContext which has a new method: setNativeHandle.

    So I am trying to make this happen. Does this make sense to you?

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with combine Qt 5.4 QOpenGLContext to native opengl context

    The addition in Qt 5.4 is if you want Qt to render within the context created by someone else, not the other way round. As I said you could try binding an FBO to the adopted context and see if the engine is able to render there. Then you can use the result as a texture in Qt part of the program (e.g. through a shared context).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    jennal (3rd December 2014)

  7. #5
    Join Date
    Nov 2014
    Posts
    6
    Thanks
    4
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: problem with combine Qt 5.4 QOpenGLContext to native opengl context

    If Qt could render in native GL context, it is OK for me. As I know, Qt could render GUI widgets in GraphicView. It seems that Qt could render widgets in GL context. Can you show me some code sample of this?

    Or the FBO solution could fit my need, I also need some code sample, because I have no idea how to begin with.

    Could you please show me some code sample or link to the documents?

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,012 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: problem with combine Qt 5.4 QOpenGLContext to native opengl context

    Quote Originally Posted by jennal View Post
    As I know, Qt could render GUI widgets in GraphicView.
    GraphicsView is a widget. And the "widgets" it renders are not really widgets.

    It seems that Qt could render widgets in GL context.
    It probably could (at least since 5.4) but I don't think that would be a good approach.
    Can you show me some code sample of this?
    No

    Or the FBO solution could fit my need, I also need some code sample, because I have no idea how to begin with.
    Use the docs Luke -- QOpenGLFramebufferObject.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 8th October 2011, 13:50
  2. Replies: 2
    Last Post: 18th November 2009, 03:43
  3. QT4 mess up the OpenGL context ?
    By fev in forum Qt Programming
    Replies: 0
    Last Post: 19th October 2009, 10:25
  4. help on openGL context
    By mickey in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2006, 19:21
  5. Context OpenGL
    By mickey in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2006, 21:13

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.