From f4ae4f41b06d61f32dbef3cac90e8e3b187ee378 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Mon, 1 Sep 2014 16:25:14 +0200 Subject: hellowindow: Set all the state for each frame MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trying to be smart and minimizing the amount of GL calls per frame to provide a good example was a mistake (in a way): There are components, like the eglfs mouse cursor, that change the context state. To make sure the example work in these cases, set the state upon each frame. Change-Id: Ief1fd7bbb0fb1955a64dac97a071b7a3d9d506d4 Reviewed-by: Jørgen Lind --- examples/opengl/hellowindow/hellowindow.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/examples/opengl/hellowindow/hellowindow.cpp b/examples/opengl/hellowindow/hellowindow.cpp index da31fee920..57eb111edb 100644 --- a/examples/opengl/hellowindow/hellowindow.cpp +++ b/examples/opengl/hellowindow/hellowindow.cpp @@ -147,6 +147,21 @@ void Renderer::render() f->glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio()); f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f); + f->glFrontFace(GL_CW); + f->glCullFace(GL_FRONT); + f->glEnable(GL_CULL_FACE); + f->glEnable(GL_DEPTH_TEST); + + m_program->bind(); + m_vbo.bind(); + + m_program->enableAttributeArray(vertexAttr); + m_program->enableAttributeArray(normalAttr); + m_program->setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3); + const int verticesSize = vertices.count() * 3 * sizeof(GLfloat); + m_program->setAttributeBuffer(normalAttr, GL_FLOAT, verticesSize, 3); + QMatrix4x4 modelview; modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f); modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f); @@ -212,18 +227,6 @@ void Renderer::initialize() m_vbo.allocate(verticesSize * 2); m_vbo.write(0, vertices.constData(), verticesSize); m_vbo.write(verticesSize, normals.constData(), verticesSize); - - QOpenGLFunctions *f = m_context->functions(); - f->glClearColor(0.1f, 0.1f, 0.2f, 1.0f); - f->glFrontFace(GL_CW); - f->glCullFace(GL_FRONT); - f->glEnable(GL_CULL_FACE); - f->glEnable(GL_DEPTH_TEST); - - m_program->enableAttributeArray(vertexAttr); - m_program->enableAttributeArray(normalAttr); - m_program->setAttributeBuffer(vertexAttr, GL_FLOAT, 0, 3); - m_program->setAttributeBuffer(normalAttr, GL_FLOAT, verticesSize, 3); } void Renderer::createGeometry() -- cgit v1.2.3