Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

OpenGL in Qt 5.1 – Part 5

void TerrainTessellationScene::render()
{
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    m_material->bind();
    QOpenGLShaderProgramPtr shader = m_material->shader();
    shader->bind();

    // Set the fragment shader display mode subroutine
    m_funcs->glUniformSubroutinesuiv(
        GL_FRAGMENT_SHADER, 1,
        &m_displayModeSubroutines[m_displayMode] );

    // Set the horizontal and vertical scales applied
    // in the tessellation stages
    shader->setUniformValue( "horizontalScale", m_horizontalScale );
    shader->setUniformValue( "verticalScale", m_verticalScale );

    // Pass in the usual transformation matrices
    QMatrix4x4 viewMatrix = m_camera->viewMatrix();
    QMatrix4x4 modelViewMatrix = viewMatrix * m_modelMatrix;
    QMatrix3x3 worldNormalMatrix = m_modelMatrix.normalMatrix();
    QMatrix3x3 normalMatrix = modelViewMatrix.normalMatrix();
    QMatrix4x4 mvp = m_camera->projectionMatrix() * modelViewMatrix;
    shader->setUniformValue( "modelMatrix", m_modelMatrix );
    shader->setUniformValue( "modelViewMatrix", modelViewMatrix );
    shader->setUniformValue( "worldNormalMatrix", worldNormalMatrix );
    shader->setUniformValue( "normalMatrix", normalMatrix );
    shader->setUniformValue( "mvp", mvp );

    // Set the lighting parameters
    QVector4D worldLightDirection( sinf( m_sunTheta * degToRad ),
                                   cosf( m_sunTheta * degToRad ),
                                   0.0f, 0.0f );
    QMatrix4x4 worldToEyeNormal( normalMatrix );
    QVector4D lightDirection = worldToEyeNormal * worldLightDirection;
    shader->setUniformValue( "light.position", lightDirection );
    shader->setUniformValue( "light.intensity",
                             QVector3D( 1.0f, 1.0f, 1.0f ) );

    // Set the material properties
    shader->setUniformValue( "material.Ka",
                             QVector3D( 0.1f, 0.1f, 0.1f ) );
    shader->setUniformValue( "material.Kd",
                             QVector3D( 1.0f, 1.0f, 1.0f ) );
    shader->setUniformValue( "material.Ks",
                             QVector3D( 0.3f, 0.3f, 0.3f ) );
    shader->setUniformValue( "material.shininess", 10.0f );

    // Render the quad as a patch
    m_vao.bind();
    shader->setPatchVertexCount( 1 );
    glDrawArrays( GL_PATCHES, 0, m_patchCount );
}

About KDAB


71 Comments

10 - Apr - 2013

HGH

10 - Apr - 2013

Sean Harmer

16 - Apr - 2013

Billy Zelsnack

24 - Apr - 2013

Julio Fernando Baffa

25 - Apr - 2013

Sean Harmer

25 - Apr - 2013

Julio Fernando Baffa

1 - Aug - 2013

Mathieu

17 - Sept - 2013

mikael

17 - Sept - 2013

Sean Harmer

20 - May - 2013

Luis

22 - May - 2013

Sean Harmer

22 - May - 2013

Luis

23 - May - 2013

Will Dobbie

24 - May - 2013

Dhi Aurrahman

24 - May - 2013

Sean Harmer

4 - Jun - 2013

Tore Slinning

11 - Jun - 2013

florian

28 - Jun - 2013

pmaynard

1 - Jul - 2013

Sean Harmer

9 - Aug - 2013

nick

11 - Aug - 2013

anm

11 - Aug - 2013

Sean Harmer

12 - Aug - 2013

glararan

14 - Aug - 2013

glararan

1 - Sept - 2013

Hardware

1 - Sept - 2013

Maiss

17 - Sept - 2013

Sean Harmer

27 - Sept - 2013

uri

27 - Sept - 2013

Sean Harmer

4 - Oct - 2013

Epxzz

14 - Oct - 2013

Irbis

14 - Oct - 2013

Sean Harmer

27 - Oct - 2013

SeVerage

28 - Oct - 2013

Sean Harmer

28 - Oct - 2013

SeVerage

28 - Oct - 2013

Irbis

class TerrainTessellationScene : public AbstractScene, protected QOpenGLFunctions_4_0_Core
m_funcs = m_context->versionFunctions();
if ( !m_funcs )
{
    qFatal("Requires OpenGL >= 4.0");
    exit( 1 );
}
m_funcs->initializeOpenGLFunctions();
initializeOpenGLFunctions();

28 - Oct - 2013

Sean Harmer

28 - Oct - 2013

Irbis

29 - Oct - 2013

Ryan

30 - Oct - 2013

Sean Harmer

30 - Oct - 2013

Ryan

30 - Oct - 2013

Sean Harmer

30 - Oct - 2013

Irbis

30 - Oct - 2013

Sean Harmer

30 - Oct - 2013

Irbis

30 - Oct - 2013

Sean Harmer

30 - Oct - 2013

Irbis

A::A()
{
QOpenGLFunctions_4_3_Core::initializeOpenGLFunctions();
b = new B;
c = new C;
}

30 - Oct - 2013

Sean Harmer

4 - Nov - 2013

Irbis

4 - Nov - 2013

Sean Harmer

4 - Nov - 2013

Irbis

15 - Nov - 2013

Elangovan D

10 - Dec - 2013

Slavina

20 - Dec - 2013

Slavina

26 - Feb - 2014

Johan

26 - Feb - 2014

Sean Harmer

4 - Mar - 2014

Bernd Dreier

4 - Mar - 2014

Sean Harmer

5 - Mar - 2014

Bernd Dreier

17 - Mar - 2014

Bernd Dreier

17 - Mar - 2014

Sean Harmer

31 - Mar - 2014

Bernd Dreier

9 - Oct - 2014

Evan

15 - Mar - 2014

sargas

22 - May - 2014

Francisco Boni

@terraintessellationscene.h:
 QOpenGLFunctions_4_3_Compatibility* m_funcs;

@terraintessellationscene.cpp:
    m_funcs = m_context->versionFunctions();
    if ( !m_funcs )
    {
        qFatal("Requires OpenGL >= 4.0");
        exit( 1 );
    }
    m_funcs->initializeOpenGLFunctions();
 // Create an OpenGL context
    m_context = new QOpenGLContext;
    m_context->setFormat( format );
    m_context->create();

22 - May - 2014

Francisco Boni

29 - Mar - 2015

HGH

29 - Mar - 2015

Sean Harmer

12 - May - 2015

Brian

12 - May - 2015

Sean Harmer

5 - Nov - 2015

Alexey

SeanHarmer

Sean Harmer

Managing Director KDAB UK