diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp index 9c6828b9024..cca08f4c917 100644 --- a/examples/opengl/textures/glwidget.cpp +++ b/examples/opengl/textures/glwidget.cpp @@ -46,9 +46,6 @@ void GLWidget::initializeGL() makeObject(); - glEnable(GL_DEPTH_TEST); - glEnable(GL_CULL_FACE); - #define PROGRAM_VERTEX_ATTRIBUTE 0 #define PROGRAM_TEXCOORD_ATTRIBUTE 1 @@ -91,6 +88,9 @@ void GLWidget::paintGL() glClearColor(clearColor.redF(), clearColor.greenF(), clearColor.blueF(), clearColor.alphaF()); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glEnable(GL_DEPTH_TEST); + glEnable(GL_CULL_FACE); + QMatrix4x4 m; m.ortho(-0.5f, +0.5f, +0.5f, -0.5f, 4.0f, 15.0f); m.translate(0.0f, 0.0f, -10.0f); @@ -98,6 +98,8 @@ void GLWidget::paintGL() m.rotate(yRot / 16.0f, 0.0f, 1.0f, 0.0f); m.rotate(zRot / 16.0f, 0.0f, 0.0f, 1.0f); + vbo.bind(); + program->bind(); program->setUniformValue("matrix", m); program->enableAttributeArray(PROGRAM_VERTEX_ATTRIBUTE); program->enableAttributeArray(PROGRAM_TEXCOORD_ATTRIBUTE); diff --git a/src/openglwidgets/qopenglwidget.cpp b/src/openglwidgets/qopenglwidget.cpp index 19230aeedd8..25c4dcf9028 100644 --- a/src/openglwidgets/qopenglwidget.cpp +++ b/src/openglwidgets/qopenglwidget.cpp @@ -1391,7 +1391,7 @@ GLuint QOpenGLWidget::defaultFramebufferObject(TargetBuffer targetBuffer) const This virtual function is called once before the first call to paintGL() or resizeGL(). Reimplement it in a subclass. - This function should set up any required OpenGL resources and state. + This function should set up any required OpenGL resources. There is no need to call makeCurrent() because this has already been done when this function is called. Note however that the framebuffer @@ -1433,6 +1433,13 @@ void QOpenGLWidget::resizeGL(int w, int h) other state is set and no clearing or drawing is performed by the framework. + \note To ensure portability, do not expect that state set in initializeGL() + persists. Rather, set all necessary state, for example, by calling + glEnable(), in paintGL(). This is because some platforms, such as WebAssembly + with WebGL, may have limitations on OpenGL contexts in some situations, which + can lead to using the context used with the QOpenGLWidget for other purposes + as well. + When \l QSurfaceFormat::StereoBuffers is enabled, this function will be called twice - once for each buffer. Query what buffer is currently bound by calling currentTargetBuffer().