Exemplo n.º 1
0
void Window::initializeGL()
{
  // Initialize OpenGL Backend
  initializeOpenGLFunctions();
  printContextInformation();

  // Set global information
  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
Exemplo n.º 2
0
//
//  OPENGL FUNCTIONS    ////////////////////////////////////////////////////////
//
void GLWidget::initializeGL()
{
    //  Initialize OpenGL Backend
    initializeOpenGLFunctions();
    printContextInformation();

    //  Application Specific Initialization
    {
        //  Create Shader (No release until VAO)
        program = new QOpenGLShaderProgram();
        program->addShaderFromSourceFile( QOpenGLShader::Vertex, 
            ":/shaders/simple.vs" );
        program->addShaderFromSourceFile( QOpenGLShader::Fragment,
            ":/shaders/simple.fs" );
        program->link();
        program->bind();

        //  Cache Uniform Locations
        model_to_world = program->uniformLocation( "model_to_world" );
        world_to_eye = program->uniformLocation( "world_to_eye" );
        eye_to_clip = program->uniformLocation( "eye_to_clip" );

        //  Create Buffer (No release until VAO)
        vertex_buffer.create();
        vertex_buffer.bind();
        vertex_buffer.setUsagePattern( QOpenGLBuffer::StaticDraw );
        vertex_buffer.allocate( sg_vertexes, sizeof( sg_vertexes ) );

        //  Create Vertex Array Object (VAO)
        vao.create();
        vao.bind();
        program->enableAttributeArray( 0 );
        program->enableAttributeArray( 1 );
        program->setAttributeBuffer( 0, GL_FLOAT, Vertex::positionOffset(), 
            Vertex::PositionTupleSize, Vertex::stride() );
        program->setAttributeBuffer( 1, GL_FLOAT, Vertex::colorOffset(), 
            Vertex::ColorTupleSize, Vertex::stride() );

        //  Release All (Order matters!!!)
        vao.release();
        vertex_buffer.release();
        program->release();
    }
}