Details
-
Bug
-
Resolution: Invalid
-
P1: Critical
-
None
-
6.7.0 Beta1
-
None
-
Asus K53SV, Intel HD Graphics 3000; Nvidia GeForce GT 540M (1 GB)
Description
The example below should draw a red triangle but it draws nothing. It prints: OpenGL version, GLSL version, and vendor:
```
OpenGL Version: 3.0 Mesa 11.2.2
GLSL Version: 1.30
OpenGL Vendor: VMware, Inc.
```
main.cpp
```
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QSurfaceFormat>
#include <QtOpenGLWidgets/QOpenGLWidget>
#include <QtOpenGL/QOpenGLBuffer>
#include <QtOpenGL/QOpenGLShaderProgram>
#include <QtWidgets/QApplication>
class OpenGLWidget : public QOpenGLWidget, private QOpenGLFunctions
{
public:
OpenGLWidget()
private:
void initializeGL() override
{
initializeOpenGLFunctions();
glClearColor(0.4f, 0.8f, 0.9f, 1.f);
qDebug() << "OpenGL Version:" << (const char*) glGetString(GL_VERSION);
qDebug() << "GLSL Version:" << (const char*) glGetString(GL_SHADING_LANGUAGE_VERSION);
qDebug() << "OpenGL Vendor:" << (const char*) glGetString(GL_VENDOR);
QString vertexShaderSource =
"attribute vec2 aPosition;\n"
"void main()\n"
"
\n";
QString fragmentShaderSource =
"#ifdef GL_ES\n"
"precision mediump float;\n"
"#endif\n"
"//out vec4 fragColor;\n"
"void main()\n"
"
\n";
m_program.create();
m_program.addShaderFromSourceCode(QOpenGLShader::ShaderTypeBit::Vertex,
vertexShaderSource);
m_program.addShaderFromSourceCode(QOpenGLShader::ShaderTypeBit::Fragment,
fragmentShaderSource);
m_program.link();
m_program.bind();
float vertPositions[] =
{ -0.5f, -0.5f, 0.5f, -0.5f, 0.f, 0.5f };
m_vertPosBuffer.create();
m_vertPosBuffer.bind();
m_vertPosBuffer.allocate(vertPositions, sizeof(vertPositions));
m_program.setAttributeBuffer("aPosition", GL_FLOAT, 0, 2);
m_program.enableAttributeArray("aPosition");
}
void paintGL() override
private:
QOpenGLShaderProgram m_program;
QOpenGLBuffer m_vertPosBuffer;
};
int main(int argc, char *argv[])
{ QApplication app(argc, argv); OpenGLWidget w; w.show(); return app.exec(); }```
pro
```
QT += core gui openglwidgets widgets
win32: LIBS += -lopengl32
CONFIG = c+17
SOURCES += \
main.cpp
```
I can active the integrated video card instead of Mesa by adding the `AA_UseDesktopOpenGL` attribute:
```
int main(int argc, char *argv[])
{
QApplication::setAttribute(Qt::ApplicationAttribute::AA_UseDesktopOpenGL);
```
The example above prints an info about the integrated card now:
```
OpenGL Version: 3.1.0 - Build 9.17.10.4459
GLSL Version: 1.40 - Intel Build 9.17.10.4459
OpenGL Vendor: Intel
```
But a triangle is white instead of red:
To active the discrete video card I should add these lines of code to main.cpp for GeForce and Radeon:
```
#ifdef _WIN32
#include <windows.h>
extern "C" __declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
extern "C" __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 0x00000001;
#endif
```
It prints this info:
```
OpenGL Version: 4.6.0 NVIDIA 391.35
GLSL Version: 4.60 NVIDIAOpenGL
Vendor: NVIDIA Corporation
```
But a triangle is still white.