Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't set desired OpenGL version in QGLWidget
    primarykey
    data
    text
    <p>I'm trying to use QGLWidget in Qt 4.8.2. I noticed that the default context QGLWidget creates doesn't show any output for OpenGL above 3.1. <a href="http://qt-project.org/wiki/How_to_use_OpenGL_Core_Profile_with_Qt" rel="noreferrer">The Qt wiki has a tutorial</a> that demonstrates using OpenGL 3.3 to draw a simple triangle. When I try to run the tutorial, I get a blank screen. If I change the OpenGL version to 3.1, I get the expected output (a red triangle).</p> <p>My video card supports OpenGL 4.2, and calling <code>QGLFormat::openGLVersionFlags()</code> before creating the QGLWidget shows that Qt detects OpenGL 4.2 and all previous desktop versions.</p> <p>Here's another minimal example:</p> <pre><code>#include &lt;QApplication&gt; #include &lt;QGLWidget&gt; #include &lt;QDebug&gt; #include &lt;QtDeclarative/qdeclarativeview.h&gt; int main(int argc, char * argv[]) { QApplication app(argc, argv); qDebug() &lt;&lt; "OpenGL Versions Supported: " &lt;&lt; QGLFormat::openGLVersionFlags(); QGLFormat qglFormat; qglFormat.setVersion(4,2); // get expected output with (3,1) and below, else blank window qglFormat.setProfile(QGLFormat::CoreProfile); qglFormat.setSampleBuffers(true); QGLWidget* qglWidget = new QGLWidget(qglFormat); QString versionString(QLatin1String(reinterpret_cast&lt;const char*&gt;(glGetString(GL_VERSION)))); qDebug() &lt;&lt; "Driver Version String:" &lt;&lt; versionString; qDebug() &lt;&lt; "Current Context:" &lt;&lt; qglWidget-&gt;format(); QDeclarativeView mainView; mainView.setViewport(qglWidget); mainView.setSource(QString("helloworld.qml")); mainView.show(); return app.exec(); } </code></pre> <p>Here's the output:</p> <pre><code>OpenGL Versions Supported: QFlags(0x1|0x2|0x4|0x8|0x10|0x20|0x40|0x1000|0x2000|0x4000|0x8000|0x10000) Driver Version String: "4.2.0 NVIDIA 295.53" Current Context: QGLFormat(options QFlags(0x1|0x2|0x4|0x10|0x20|0x80|0x200|0x400) , plane 0 , depthBufferSize 24 , accumBufferSize 16 , stencilBufferSize 8 , redBufferSize 8 , greenBufferSize 8 , blueBufferSize 8 , alphaBufferSize -1 , samples 4 , swapInterval 0 , majorVersion 4 , minorVersion 2 , profile 1 ) </code></pre> <p>The <code>QFlags()</code> enum list on the first line describes the OpenGL versions supported. The list shows I support all variants except for OpenGL/ES versions. QFlags() on the third line describes format options (alpha channel, stencil buffer, etc).</p> <p>Anyone know why QGLWidget won't work with anything >= 3.1? I'm on Linux, have an Nvidia GT440, and glxinfo shows it supports OpenGL 4.2.0. The driver version is printed in the sample output above. I'm not too sure what else to try.</p> <p><em>Edit: I made some pretty bad mistakes/assumptions with my explanation of the problem before this edit. The issue is still similar, but hopefully makes a bit more sense now. Sorry for any confusion.</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload