How to use QSurfaceFormat instead of QGLFormat.



  • "QSurfaceFormat":http://qt-project.org/doc/qt-5.1/qtgui/qsurfaceformat.html
    http://qt-project.org/doc/qt-5.1/qtopengl/qglformat.html

    in the document of "QSurfaceFormat::depthBufferSize()":http://qt-project.org/doc/qt-5.1/qtgui/qsurfaceformat.html#depthBufferSize
    There is dead functions setDepth() and depth().
    @
    int QSurfaceFormat::depthBufferSize() const
    Returns the depth buffer size.
    See also setDepthBufferSize(), setDepth(), and depth().
    @

    I want to know how to setDepth in QSurfaceFormat.



  • @
    QSurfaceFormat f;
    f.setDepthBufferSize( 24 );
    @

    Looks like the docs are out of date and contain an error. I'll fix them.



  • Fixed in https://codereview.qt-project.org/#change,68934 Thanks for the heads up.



  • [quote author="ZapB" date="1382522966"]@
    QSurfaceFormat f;
    f.setDepthBufferSize( 24 );
    @

    Looks like the docs are out of date and contain an error. I'll fix them.[/quote]

    Thanks for your answer, but 24 is a magical number, where does it comes from?

    indeed, I want a equivalent for
    @
    glutInitDisplayMode(GLUT_ALPHA | GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL);
    @
    I have a piece of opengl code(generated by SCADE, that's why I can not implement it directly in Qt) code to running under QWinodw. The problem is that it's didn't running fine, so I wanna to know what kinds of initialization and running parameters should be set.



  • 24 is the bit depth of the depth buffer being requested, it's not a magic number.

    To get the equivalent to what you want I think you need this or some variation of it:

    @
    QSurfaceFormat f;
    f.setDepthBufferSize( 24 ); // or 16, or 32 depending on what precision you want
    f.setStencilBufferSize( 8 );
    @

    The default should automatically include an RGBA color buffer and double buffering.



  • Herder, thanks a lot, how about the alphaBufferSize? I want a value for it. Indeed, I am a newbie about opengl, sorry about the naive question.



  • @
    f.setAlphaBufferSize(8);
    @

    although I think that is also the default (RGBA color buffer with 8 bits per channel).



  • Do

    @
    qDebug() << f;
    @

    to check both what you request and then after the context is created to see what you actually got back:

    @
    QSurfaceFormat actualFormat = m_context->format();
    qDebug() << actualFormat;
    @



  • Hi, Robot, thanks for your vivid answer. Now I am facing a serious problem about Qt 5.x opengl works with SCADE, when I using Qt 5.x/vs2010-x86 (QWindow/QGLWidget) to show a SCADE opengl rendering staff, it's can show it correctly, but the problem is it's flashing.
    With the same copy of code running under Qt 4.8.3/vs2008-x86, it's works fine. So I am confused, and don't know if this is a bug or there is something i need to take care of. Ask for advice. Really appreciate for this.



  • Sorry, I have no idea without seeing some code that exhibits the problem. Can you make a small compilable example that shows the issue please?



  • [quote author="ZapB" date="1382597848"]Sorry, I have no idea without seeing some code that exhibits the problem. Can you make a small compilable example that shows the issue please?[/quote]

    "OpenGL flashing bug":https://bugreports.qt-project.org/browse/QTBUG-34295
    This is my bug report, I attached the source code that can be compiled, all the dependence are included, except it's only works with vs2008/vs2010/x86/opengl version.



  • OK thanks. I'll try to take a look soon.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.