FWIW here's how I'm doing it.

I set the default format at startup with my requested format:

   void  initOpenGL()
   {
      QSurfaceFormat format;

      format.setVersion( 3, 3 );
      format.setProfile( QSurfaceFormat::CoreProfile );

      format.setDepthBufferSize( 24 );
      format.setSamples( 4 );
      format.setStencilBufferSize( 8 );

      QSurfaceFormat::setDefaultFormat( format );
   }

Then I call this to dump some info so I know what I'm getting:

   void  openGLInfo()
   {
      // we need a QSurface active to get our GL functions from the context
      QWindow  surface;
      surface.setSurfaceType( QSurface::OpenGLSurface );
      surface.create();

      QOpenGLContext context;
      context.create();
      context.makeCurrent( &surface );

      QOpenGLFunctions  *funcs = context.functions();
      funcs->initializeOpenGLFunctions();

      qInfo() << "OpenGL Info";
      qInfo() << "  Vendor: " << reinterpret_cast<const char
*>(funcs->glGetString( GL_VENDOR ));
      qInfo() << "  Renderer: " << reinterpret_cast<const char
*>(funcs->glGetString( GL_RENDERER ));
      qInfo() << "  Version: " << reinterpret_cast<const char
*>(funcs->glGetString( GL_VERSION ));
      qInfo() << "  Shading language: " << reinterpret_cast<const char
*>(funcs->glGetString( GL_SHADING_LANGUAGE_VERSION ));
      qInfo() << "  Requested format: " << QSurfaceFormat::defaultFormat();
      qInfo() << "  Current format:   " << context.format();
   }

Which gives me something like this:

OpenGL Info
  Vendor:  NVIDIA Corporation
  Renderer:  NVIDIA GeForce GTX 780M OpenGL Engine
  Version:  4.1 NVIDIA-10.4.2 310.41.35f01
  Shading language:  4.10
  Requested format:  QSurfaceFormat(version 3.3, options QFlags(),
depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize
-1, alphaBufferSize -1, stencilBufferSize 8, samples 4, swapBehavior 0,
swapInterval 1, profile  1)
  Current format:    QSurfaceFormat(version 4.1, options QFlags(),
depthBufferSize 24, redBufferSize 8, greenBufferSize 8, blueBufferSize 8,
alphaBufferSize -1, stencilBufferSize 8, samples 4, swapBehavior 2,
swapInterval 1, profile  1)


(Note: This only gives me a 3.0 context on VMware Fusion 8.1 running
Windows 7 - should support 3.3 - so maybe I'm doing something wrong?)

If anyone has any suggestions for improvement it would be most welcome!


---
Andy Maloney  //  https://asmaloney.com
twitter ~ @asmaloney <https://twitter.com/asmaloney>


On Tue, May 17, 2016 at 4:05 AM, Giuseppe D'Angelo <dange...@gmail.com>
wrote:

> On Tue, May 17, 2016 at 9:59 AM, Boudewijn Rempt <b...@valdyas.org> wrote:
> > Hm... But when I tried that with a nonsense version, say 9.9, I
> > got 9.9 back. Maybe I made a mistake, though. I copied the functions
> > check approach from the tesselation example from KDab's website...
>
> Did you _create_ the context or just set a format and asked for it
> back immediately?
>
> Using the functions for just testing whether you've got a certain GL
> version seems to me to be doing it the other way around. Then, sure,
> once you're happy with the version you need to grab them and use them.
>
> --
> Giuseppe D'Angelo
> _______________________________________________
> Interest mailing list
> Interest@qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to