Exemple #1
0
void Viewer::attrib_buffers(QGLViewer* viewer)
{
    QMatrix4x4 mvpMatrix;
    QMatrix4x4 mvMatrix;
    double mat[16];
    viewer->camera()->getModelViewProjectionMatrix(mat);
    for(int i=0; i < 16; i++)
    {
        mvpMatrix.data()[i] = (float)mat[i];
    }
    viewer->camera()->getModelViewMatrix(mat);
    for(int i=0; i < 16; i++)
    {
        mvMatrix.data()[i] = (float)mat[i];
    }
    // define material
     QVector4D	ambient(0.25f, 0.20725f, 0.20725f, 0.922f);
     QVector4D	diffuse( 1.0f,
                            0.829f,
                            0.829f,
                            0.922f );

    QVector4D	specular(  0.6f,
                            0.6f,
                            0.6f,
                            1.0f );

    QVector4D	position(0.0f,0.0f,1.0f,1.0f );
     GLfloat shininess =  11.264f;


    rendering_program.bind();
    mvpLocation = rendering_program.uniformLocation("mvp_matrix");
    mvLocation = rendering_program.uniformLocation("mv_matrix");
    colorLocation = rendering_program.uniformLocation("color");
    lightLocation[0] = rendering_program.uniformLocation("light_pos");
    lightLocation[1] = rendering_program.uniformLocation("light_diff");
    lightLocation[2] = rendering_program.uniformLocation("light_spec");
    lightLocation[3] = rendering_program.uniformLocation("light_amb");
    lightLocation[4] = rendering_program.uniformLocation("spec_power");

    rendering_program.setUniformValue(lightLocation[0], position);
    rendering_program.setUniformValue(lightLocation[1], diffuse);
    rendering_program.setUniformValue(lightLocation[2], specular);
    rendering_program.setUniformValue(lightLocation[3], ambient);
    rendering_program.setUniformValue(lightLocation[4], shininess);
    rendering_program.setUniformValue(mvpLocation, mvpMatrix);
    rendering_program.setUniformValue(mvLocation, mvMatrix);


    rendering_program.release();

    rendering_program_points.bind();

    mvpLocation_points = rendering_program_points.uniformLocation("mvp_matrix");
    colorLocation_points = rendering_program_points.uniformLocation("color");
    rendering_program_points.setUniformValue(mvpLocation_points, mvpMatrix);

    rendering_program_points.release();
}
void Scene_implicit_function_item::attrib_buffers(Viewer* viewer) const
{
    QMatrix4x4 mvpMatrix;
    QMatrix4x4 fMatrix;
    double mat[16];
    viewer->camera()->getModelViewProjectionMatrix(mat);
    for(int i=0; i < 16; i++)
    {
        mvpMatrix.data()[i] = (float)mat[i];
    }
    frame_->getMatrix(mat);
    for(int i=0; i < 16; i++)
    {
        fMatrix.data()[i] = (float)mat[i];
    }

    rendering_program.bind();
    colorLocation[0] = rendering_program.uniformLocation("color");
    mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix");
    rendering_program.setUniformValue(mvpLocation[0], mvpMatrix);;
    rendering_program.release();

    tex_rendering_program.bind();
    colorLocation[1] = tex_rendering_program.uniformLocation("color");
    f_Location = tex_rendering_program.uniformLocation("f_matrix");
    mvpLocation[1] = tex_rendering_program.uniformLocation("mvp_matrix");
    tex_rendering_program.setUniformValue(mvpLocation[1], mvpMatrix);;
    tex_rendering_program.setUniformValue(f_Location, fMatrix);;
    tex_rendering_program.release();

}
void Dragon2Widget::paintGL()
{
    qglClearColor(Qt::white);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_ALPHA_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    // use the OpenGL shader program for painting
    glUseProgram(_program);

    // set model matrix
    glUniformMatrix4fv(_modelMatrixLocation, 1, GL_FALSE, _modelMatrix.data());

    // set view matrix
    QMatrix4x4 viewMatrix;
    viewMatrix.setToIdentity();
    viewMatrix.lookAt(QVector3D(0, 0, -1000), QVector3D(0, 0, 0), QVector3D(0, -1, 0));
    glUniformMatrix4fv(_viewMatrixLocation, 1, GL_FALSE, viewMatrix.data());

    // set projection matrix
    QMatrix4x4 projectionMatrix;
    projectionMatrix.setToIdentity();
    projectionMatrix.perspective(30, (float)width()/height(), 0.01f, 1e5f);
    glUniformMatrix4fv(_projectionMatrixLocation, 1, GL_FALSE, projectionMatrix.data());

    // bind ArrayBuffer to _vertBuffer
    glBindBuffer(GL_ARRAY_BUFFER, _vertBuffer);
    // enable vertex attribute "position" (bound to 0 already)
    glEnableVertexAttribArray(0); 
    // set the data of vertex attribute "position" using current ArrayBuffer
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(_vertices.first()), 0);
    // enable vertex attribute "normal" (bound to 1 already)
    glEnableVertexAttribArray(1);
    // set the data of vertex attribute "normal" using current ArrayBuffer
    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, sizeof(_vertices.first()), (void*)(3 * sizeof(float)));

    // bind ElementArrayBuffer to _triangleIndicesBuffer
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _triangleIndicesBuffer);
    // draw mesh using the indices stored in ElementArrayBuffer
    glDrawElements(GL_TRIANGLES, _triangleIndices.size(), GL_UNSIGNED_INT, 0);

    // disable vertex attributes
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);

    // unbind buffers
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

    // restore states
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_ALPHA_TEST);
    glDisable(GL_BLEND);
}
Exemple #4
0
void Viewer::attrib_buffers(CGAL::QGLViewer* viewer)
{
  QMatrix4x4 mvpMatrix;
  QMatrix4x4 mvMatrix;
  double mat[16];
  viewer->camera()->getModelViewProjectionMatrix(mat);
  for(int i=0; i < 16; i++)
  {
    mvpMatrix.data()[i] = (float)mat[i];
  }
  viewer->camera()->getModelViewMatrix(mat);
  for(int i=0; i < 16; i++)
  {
    mvMatrix.data()[i] = (float)mat[i];
  }
  // define material
  QVector4D diffuse( 0.9f,
                     0.9f,
                     0.9f,
                     0.9f );

  QVector4D specular( 0.0f,
                      0.0f,
                      0.0f,
                      1.0f );


  QVector4D position((bb.xmax()-bb.xmin())/2, (bb.ymax()-bb.ymin())/2,bb.zmax(), 0.0 );
  GLfloat shininess =  1.0f;

  rendering_program.bind();
  mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix");
  mvLocation = rendering_program.uniformLocation("mv_matrix");
  lightLocation[0] = rendering_program.uniformLocation("light_pos");
  lightLocation[1] = rendering_program.uniformLocation("light_diff");
  lightLocation[2] = rendering_program.uniformLocation("light_spec");
  lightLocation[3] = rendering_program.uniformLocation("light_amb");
  lightLocation[4] = rendering_program.uniformLocation("spec_power");

  rendering_program.setUniformValue(lightLocation[0], position);
  rendering_program.setUniformValue(lightLocation[1], diffuse);
  rendering_program.setUniformValue(lightLocation[2], specular);
  rendering_program.setUniformValue(lightLocation[3], ambient);
  rendering_program.setUniformValue(lightLocation[4], shininess);
  rendering_program.setUniformValue(mvpLocation[0], mvpMatrix);
  rendering_program.setUniformValue(mvLocation, mvMatrix);

  rendering_program.release();
  rendering_program_p_l.bind();
  mvpLocation[1] = rendering_program_p_l.uniformLocation("mvp_matrix");
  colorLocation = rendering_program_p_l.uniformLocation("color");
  rendering_program.setUniformValue(mvpLocation[1], mvpMatrix);
  rendering_program_p_l.release();
}
Exemple #5
0
void PipeLine::apply(ShaderProgram *shader)
{
	initializeOpenGLFunctions();
	QMatrix4x4 MVP = m_projection*m_view*m_model;
	QMatrix4x4 MV = m_view * m_model;
	shader->setUniformMat4v("g_MVP_matrix", MVP.data());
	shader->setUniformMat4v("g_MV_matrix", MV.data());
	shader->setUniformMat4v("g_model_matrix", m_model.data());
	shader->setUniformMat4v("g_projection_matrix",m_projection.data());
	shader->setUniform3Float("g_eye_position",m_eyePosition.x(),m_eyePosition.y(), m_eyePosition.z());
	shader->setUniform3Float ("g_eye_dir",m_eyeDirection.x (),m_eyeDirection.y (),m_eyeDirection.z ());
}
Exemple #6
0
void CAnm2D::convMat(double *ret, const QMatrix4x4 &mat)
{
	const qreal *p = mat.data() ;
	for ( int i = 0 ; i < 16 ; i ++ ) {
		ret[i] = p[i] ;
	}
}
Exemple #7
0
void LogoRenderer::vao_vbo_glDrawArrays()
{
    // Render
    glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    // Draw our first triangle
    glUseProgram(shaderProgram);

    QMatrix4x4 modelview;
    modelview.rotate(m_fAngle, 0.0f, 1.0f, 0.0f);
    modelview.rotate(m_fAngle, 1.0f, 0.0f, 0.0f);
    modelview.rotate(m_fAngle, 0.0f, 0.0f, 1.0f);
    modelview.scale(m_fScale);
    modelview.translate(0.0f, -0.2f, 0.0f);

    // Uniform offset
    // Get matrix's uniform location and set matrix
    GLint transformLoc = glGetUniformLocation(shaderProgram, "transform");
    glUniformMatrix4fv(transformLoc, 1, GL_FALSE, modelview.data());
    //            glUniform1f(glGetUniformLocation(ourShader.Program, "xOffset"), offset);

    glBindVertexArray(VAO);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glBindVertexArray(0);
}
Exemple #8
0
void Scene::pointLightPass(RenderTarget *target)
{
    if(!this->pointLights.empty ())
    {
        for(int i =0;i<pointLights.size ();i++)
        {
            ShaderProgram * shader = ShaderPool::getInstance ()->get("point_light_pass");
            shader->use ();
            PointLight * light = this->pointLights[i];
            light->apply (shader,0);

            m_quad->setShaderProgram (shader);
            QMatrix4x4 m;
            m.setToIdentity ();
            auto camera = target->camera ();
            shader->setUniformMat4v ("g_MVP_matrix",m.data ());
            shader->setUniform2Float ("g_screen_size",1024,768);
            shader->setUniformInteger ("g_color_map",0);
            shader->setUniformInteger ("g_position_map",1);
            shader->setUniformInteger ("g_normal_map",2);
            shader->setUniform3Float ("g_eye_position",
                                      camera->pos ().x(),
                                      camera->pos ().y(),
                                      camera->pos ().z());
            m_quad->draw (true);
        }
    }
}
Exemple #9
0
void Render::rotToFloatArray(float conv[16]) {
	QMatrix4x4 mat = rotToMatrix();
	qreal *from = mat.data();
	for (int i = 0; i < 16; i++) {
		conv[i] = from[i];
	}
}
Exemple #10
0
void Scene::directionLightPass(RenderTarget *target)
{
    ShaderProgram * shader =ShaderPool::getInstance ()->get("dir_light_pass");
    shader->use ();
    int texture_offset = 5;

    for(int i = 0 ;i<4;i++)
    {
        directionLight.getCSM_FBO (i)->BindForReading(GL_TEXTURE0+i+texture_offset);
        char GLSL_shadowMap_name [30];
        sprintf(GLSL_shadowMap_name,"g_shadow_map[%d]",i);
        directionLight.getCSM_FBO (i)->applyShadowMapTexture (shader,i+texture_offset,GLSL_shadowMap_name);
    }

    QMatrix4x4 m;
    m.setToIdentity ();
    m_quad->setShaderProgram (shader);
    shader->setUniformMat4v ("g_MVP_matrix",m.data ());
    shader->setUniform2Float ("g_screen_size",1024,768);
    shader->setUniformInteger ("g_color_map",0);
    shader->setUniformInteger ("g_position_map",1);
    shader->setUniformInteger ("g_normal_map",2);

    shader->setUniformInteger ("g_depth_map",4);//for depth

    auto camera = target->camera ();
    if(camera)
    {
        shader->setUniform3Float ("g_eye_position",
                                  camera->pos ().x(),
                                  camera->pos ().y(),
                                  camera->pos ().z());
    }

    QMatrix4x4 lightView;
    lightView.setToIdentity();


    QVector3D lightDir = directionLight.getDirection ();
    QVector3D pos = QVector3D(0,0,0);
    lightView.lookAt(pos,lightDir,QVector3D(0,1,0));

    for(int i =0 ;i <4 ;i++)
    {
        if(!camera) break;
        auto split_frustum_aabb = camera->getSplitFrustumAABB (i);
        split_frustum_aabb.transForm (target->camera()->getModelTrans ());
        split_frustum_aabb.transForm (lightView);
        auto matrix = getCropMatrix (split_frustum_aabb);
        QMatrix4x4 light_vp;
        light_vp = matrix * lightView ;
        char GLSL_light_VP_name [30];
        sprintf(GLSL_light_VP_name,"g_light_vp_matrix[%d]",i);
        shader->setUniformMat4v (GLSL_light_VP_name,light_vp.data ());
    }
    this->directionLight.apply(shader);
    this->ambientLight.apply(shader);
    m_quad->draw (true);
}
//points position
void PagShaderProgram::setUniform(std::string name, QMatrix4x4 value)
{
    GLint location = glGetUniformLocation(program, name.c_str());
    if (location >= 0) {
        glUniformMatrix4fv(location, 1, GL_FALSE, value.data());
    } else {
        qDebug() << "No es posible encontrar localización para: " << name.c_str();
    }
}
Exemple #12
0
QMatrix4x4 Qgs3DUtils::stringToMatrix4x4( const QString &str )
{
  QMatrix4x4 m;
  float *d = m.data();
  QStringList elems = str.split( ' ' );
  for ( int i = 0; i < 16; ++i )
    d[i] = elems[i].toFloat();
  return m;
}
void DragonWidget::paintGL()
{
    makeCurrent();

    qglClearColor(Qt::white);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glEnable(GL_DEPTH_TEST);
    glEnable(GL_ALPHA_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glShadeModel(GL_SMOOTH);
    
    // set model-view matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    QMatrix4x4 viewMatrix;
    viewMatrix.lookAt(QVector3D(0, 0, -1000), QVector3D(0, 0, 0), QVector3D(0, -1, 0));
    glMultMatrixf(viewMatrix.data());
    glMultMatrixf(_modelMatrix.data()); // now model-view matrix = lookAt(...) * _modelMatrix

    // set projection matrix 
    // (projection matrix is often set in resizeGL(width, height) functions, 
    //  since it only relies on the size of the window in most cases)
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    QMatrix4x4 projectionMatrix;
    projectionMatrix.perspective(30.0f, (float)width() / height(), 0.01f, 1e5f);
    glMultMatrixf(projectionMatrix.data());

    // draw mesh
    glBegin(GL_TRIANGLES);
    for(int vid : _triangleIndices)
    {
        glColor3fv(&(_vertices[vid].normal[0]));
        glVertex3fv(&(_vertices[vid].position[0]));
    }
    glEnd();    


    glDisable(GL_DEPTH_TEST);
    glDisable(GL_ALPHA_TEST);
    glDisable(GL_BLEND);
} 
Exemple #14
0
QMatrix4x4 Object3D::glGetMatrix(GLenum fetchType)
{
    QMatrix4x4 ret;
    GLfloat mat[16];
    glGetFloatv(fetchType, mat);
    //float *m = ret.data();
    qreal *m = ret.data();
    for (int index = 0; index < 16; ++index)
        m[index] = mat[index];

    return ret;
}
void MusikQuadRender::initializeTexGeometry()
{
    ShapeData shape = ShapeGenerator::makeQuadTex();

    tVertex.create();
    tVertex.bind();
    tVertex.setUsagePattern(QOpenGLBuffer::StaticDraw);
    tVertex.allocate(shape.vertices,shape.numVertices*sizeof(Vertex));

    tObject.create();
    tObject.bind();

    programm->enableAttributeArray(vposAttr);
    programm->enableAttributeArray(vcolAttr);
    programm->setAttributeBuffer(vposAttr,GL_FLOAT,Vertex::positionOffset(),Vertex::PositionTupleSize,Vertex::stride());
    programm->setAttributeBuffer(vcolAttr,GL_FLOAT,Vertex::colorOffset(),Vertex::ColorTupleSize,Vertex::stride());

    tIndex.create();
    tIndex.bind();

    tIndex.setUsagePattern(QOpenGLBuffer::StaticDraw);
    tIndex.allocate(shape.indices,shape.indexBufferSize());

    numIndx = shape.numIndices;

    tVertex.release();
    tObject.release();

    tTransform.create();
    tTransform.bind();
    tTransform.setUsagePattern(QOpenGLBuffer::StaticDraw);
    tTransform.allocate(quadTransforms,sizeof(QMatrix4x4)*numQuads);

    tObject.bind();



    programm->setAttributeBuffer(vmatrixAttr,GL_FLOAT,sizeof(QVector4D)*0,4,sizeof(QMatrix4x4));

    QMatrix4x4 mat;
    programm->setAttributeValue(vmatrixAttr,mat.data(),4,4);



    tObject.release();
    tTransform.release();

    shape.cleanup();
}
QMatrix4x4 AndroidSurfaceTexture::getTransformMatrix()
{
    QMatrix4x4 matrix;
    if (!m_surfaceTexture.isValid())
        return matrix;

    QJNIEnvironmentPrivate env;

    jfloatArray array = env->NewFloatArray(16);
    m_surfaceTexture.callMethod<void>("getTransformMatrix", "([F)V", array);
    env->GetFloatArrayRegion(array, 0, 16, matrix.data());
    env->DeleteLocalRef(array);

    return matrix;
}
void Volume_plane_intersection::attrib_buffers(Viewer* viewer) const
{
    QMatrix4x4 mvpMatrix;
    double mat[16];
    viewer->camera()->getModelViewProjectionMatrix(mat);
    for(int i=0; i < 16; i++)
    {
        mvpMatrix.data()[i] = (float)mat[i];
    }

    rendering_program.bind();
    mvpLocation[0] = rendering_program.uniformLocation("mvp_matrix");
    rendering_program.setUniformValue(mvpLocation[0], mvpMatrix);
    rendering_program.release();
}
Exemple #18
0
void Scene::pickBright()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    ShaderProgram * shader =ShaderPool::getInstance ()->get("pick_bright");
    shader->use ();
    QMatrix4x4 m;
    m.setToIdentity ();
    m_quad->setShaderProgram (shader);
    shader->setUniformMat4v ("g_MVP_matrix",m.data ());
    shader->setUniform2Float ("g_screen_size",1024,768);
    shader->setUniformInteger ("g_color_map",0);
    shader->setUniformInteger ("g_position_map",1);
    shader->setUniformInteger ("g_normal_map",2);
    this->directionLight.apply(shader);
    this->ambientLight.apply(shader);
    m_quad->draw (true);
}
Exemple #19
0
void Scene::gaussianBlur_V(float size)
{
    ShaderProgram * shader =ShaderPool::getInstance ()->get("gaussian_blur_v");
    shader->use ();
    QMatrix4x4 m;
    m.setToIdentity ();
    m_quad->setShaderProgram (shader);
    shader->setUniformFloat ("g_blur_size",size);
    shader->setUniformMat4v ("g_MVP_matrix",m.data ());
    shader->setUniform2Float ("g_screen_size",1024,768);
    shader->setUniformInteger ("g_color_map",0);
    shader->setUniformInteger ("g_position_map",1);
    shader->setUniformInteger ("g_normal_map",2);
    this->directionLight.apply(shader);
    this->ambientLight.apply(shader);
    m_quad->draw (true);
}
Exemple #20
0
QMatrix4x4 DataObject::parse4x4Matrix(QString str)
{
    QString sub = str.mid(1,str.length()-2);
    QStringList ls = sub.split(QRegExp("\\] *, *\\["));
    QMatrix4x4 matrix;
    int index = 0;
    float* data = matrix.data();
    QStringList::iterator iter;
    for (iter = ls.begin() ;iter != ls.end() ; iter++) {
        QString out = *iter;
        std::vector<double> vd = parseVector(out);
        data[index] = vd[0];
        data[index+1] = vd[1];
        data[index+2] = vd[2];
        data[index+3] = vd[3];
        index+=4;
    }
    return matrix;
}
Exemple #21
0
void GLWidget::paintGL()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	// Translate object coordinates to model coordinates
	QMatrix4x4 modelMatrix;
	modelMatrix.translate(m_translateX, m_translateY, m_currentZoom);

	// Viewmatrix
	QMatrix4x4 viewMatrix;
	viewMatrix.rotate(m_cameraAngleY, 0.0, 1.0, 0.0);
	viewMatrix.rotate(m_cameraAngleX, 1.0, 0.0, 0.0);
	viewMatrix.rotate(m_cameraAngleZ, 0.0, 0.0, 1.0);

	QMatrix4x4 modelViewMatrix = modelMatrix * viewMatrix;

    glLoadMatrixd(modelViewMatrix.data());

	m_mapRenderer.render(this);
	QGLWidget::swapBuffers();
}
Exemple #22
0
void Scene::attrib_buffers(QGLViewer* viewer)
{
    QMatrix4x4 mvpMatrix;
    double mat[16];
    viewer->camera()->getModelViewProjectionMatrix(mat);
    for(int i=0; i < 16; i++)
    {
        mvpMatrix.data()[i] = (float)mat[i];
    }
    rendering_program.bind();
    mvpLocation = rendering_program.uniformLocation("mvp_matrix");
    fLocation = rendering_program.uniformLocation("f_matrix");
    colorLocation = rendering_program.uniformLocation("color");
    rendering_program.setUniformValue(mvpLocation, mvpMatrix);
    rendering_program.release();

    tex_rendering_program.bind();
    tex_mvpLocation = tex_rendering_program.uniformLocation("mvp_matrix");
    tex_fLocation = tex_rendering_program.uniformLocation("f_matrix");
    tex_rendering_program.setUniformValue(tex_mvpLocation, mvpMatrix);
    tex_rendering_program.release();
}
/**
 * Register the commands that render the entity.
 */
void VkcEntity::render(VkCommandBuffer commandBuffer, MgBuffer uniformBuffer, QMatrix4x4 vpMatrix, const VkcDevice *device)
{
    // Wiggle, wiggle, wiggle.
    position += QVector3D(dir, 0.0f, 0.0f);
    float pos = position.x();

    if(pos > 0.1f || pos < -0.1f)
        dir *= -1.0f;

    // Calculate model matrix.
    QMatrix4x4 modelMatrix;
    modelMatrix.translate(position);
    modelMatrix.rotate(rotation);
    modelMatrix.scale(scale);

    // Calculate MVP matrix.
    QMatrix4x4 mvpMatrix = vpMatrix * modelMatrix;

    // Map uniform buffer memory to host.
    void *data = nullptr;
    vkMapMemory(device->logical, uniformBuffer.memory, 0, VK_WHOLE_SIZE, 0, &data);

    // Copy data to the buffer.
    memcpy(data, mvpMatrix.data(), 16 * sizeof(float));

    // Unmap memory.
    vkUnmapMemory(device->logical, uniformBuffer.memory);

    // Bind vertex and index bufffer.
    VkDeviceSize vboOffsets[] = {0};
    uint32_t iboOffset = vertices.size() * sizeof(VkVertex);

    vkCmdBindVertexBuffers(commandBuffer, 0, 1, &buffer.handle, vboOffsets);
    vkCmdBindIndexBuffer(commandBuffer, buffer.handle, iboOffset, VK_INDEX_TYPE_UINT32);

    // Draw entity.
    vkCmdDrawIndexed(commandBuffer, indices.size(), 1, 0, 0, 0);
}
Exemple #24
0
void Scene::spotLightPass(RenderTarget * target)
{
    if(!this->spotLights.empty ())
    {
        for(int i =0;i<spotLights.size ();i++)
        {
            PointLight * light = this->spotLights[i];
            light->shadowFBO ()->BindForReading(GL_TEXTURE3);
            ShaderProgram * shader = ShaderPool::getInstance ()->get("spot_light_pass");
            shader->use ();
            light->shadowFBO ()->applyShadowMapTexture (shader,3);

            light->apply (shader,0);
            m_quad->setShaderProgram (shader);
            QMatrix4x4 m;
            m.setToIdentity ();
            auto camera = target->camera ();
            shader->setUniformMat4v ("g_MVP_matrix",m.data ());
            shader->setUniform2Float ("g_screen_size",1024,768);
            shader->setUniformInteger ("g_color_map",0);
            shader->setUniformInteger ("g_position_map",1);
            shader->setUniformInteger ("g_normal_map",2);
            shader->setUniform3Float ("g_eye_position",
                                      camera->pos ().x(),
                                      camera->pos ().y(),
                                      camera->pos ().z());
            QMatrix4x4 lightView;
            lightView.setToIdentity();
            lightView.lookAt(spotLights[0]->getPos(),this->spotLights[0]->getPos()+this->spotLights[0]->getDirection(),QVector3D(0,1,0));
            QMatrix4x4 light_vp;
            light_vp = camera->getProjection () * lightView ;
            shader->setUniformMat4v ("g_light_vp_matrix",light_vp.data ());
            m_quad->draw (true);
        }
    }
}
Exemple #25
0
void Scene::deferredRendering(RenderTarget * target)
{
    if(target->isEnableClipPlane ())
    {
        glEnable(GL_CLIP_PLANE0);
        glClipPlane(GL_CLIP_PLANE0, target->getClipPlane());
    }
    if(!this->spotLights.empty ())
    {
        this->shadowPassForSpot(spotLights[0],target);
    }
    if(this->directionLight.getIntensity ()>0)
    {
        this->shadowPassDirectional (target);
    }

    geometryPass(target);
    if(target->isEnableClipPlane ())
    {
        glDisable(GL_CLIP_PLANE0);
    }
    glEnable(GL_BLEND);
    glBlendEquation(GL_FUNC_ADD);
    glBlendFunc(GL_ONE, GL_ONE);
    target->getGBuffer ()->BindForReading(bloom_fbo1->buffer ());

    lightPass(target);

    bloom_fbo1->BindForReading (bloom_fbo2);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    pickBright();
    bloom_fbo2->BindForReading (bloom_fbo3);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    gaussianBlur_H (2);
    bloom_fbo3->BindForReading (NULL);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    gaussianBlur_V (2);

    if(target->type () == RenderTarget::TargetType::ON_SCREEN)
    {
        bloom_fbo1->BindForReading (NULL);
    }
    else
    {
        bloom_fbo1->BindForReading (target->resultBuffer ());
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    }

    ShaderProgram * shader =ShaderPool::getInstance ()->get("deffered_simple");
    shader->use ();
    QMatrix4x4 m;
    m.setToIdentity ();
    m_quad->setShaderProgram (shader);
    auto camera =target->camera ();
    shader->setUniformMat4v ("g_MVP_matrix",m.data ());
    shader->setUniform2Float ("g_screen_size",1024,768);
    shader->setUniformInteger ("g_color_map",0);
    shader->setUniformInteger ("g_position_map",1);
    shader->setUniformInteger ("g_normal_map",2);
    if(camera)
    {
        shader->setUniform3Float ("g_eye_position",
                                  camera->pos ().x(),
                                  camera->pos ().y(),
                                  camera->pos ().z());
    }
    m_quad->draw (true);
}
Exemple #26
0
void SegmentGL::RenderContour(Segment *seg, QMatrix4x4 projection, QMatrix4x4 modelview, int width, int height)
{

    QVector3D vec;
    QVector3D pos;
    QVector<GLfloat> positions;
    QEci qeci;


    CalculateSegmentContour(&positions, seg->cornerpointfirst1.latitude, seg->cornerpointfirst1.longitude, seg->cornerpointlast1.latitude, seg->cornerpointlast1.longitude);
    CalculateSegmentContour(&positions,seg->cornerpointlast1.latitude, seg->cornerpointlast1.longitude, seg->cornerpointlast2.latitude, seg->cornerpointlast2.longitude);
    CalculateSegmentContour(&positions, seg->cornerpointlast2.latitude, seg->cornerpointlast2.longitude, seg->cornerpointfirst2.latitude, seg->cornerpointfirst2.longitude);
    CalculateSegmentContour(&positions,seg->cornerpointfirst2.latitude, seg->cornerpointfirst2.longitude, seg->cornerpointfirst1.latitude, seg->cornerpointfirst1.longitude);

    seg->qsgp4->getPosition(seg->minutes_since_state_vector, qeci);
    QGeodetic qgeo = qeci.ToGeo();
    double lat1 = qgeo.latitude;
    double lon1 = qgeo.longitude;

    seg->qsgp4->getPosition(seg->minutes_since_state_vector + seg->minutes_sensing, qeci);
    qgeo = qeci.ToGeo();
    double lat2 = qgeo.latitude;
    double lon2 = qgeo.longitude;

    CalculateSegmentContour(&positions, lat1, lon1, lat2, lon2);

    positionsBuf.bind();
    positionsBuf.write(0, positions.data(), positions.size() * sizeof(GLfloat));
    positionsBuf.release();

    QOpenGLVertexArrayObject::Binder vaoBinder(&vao);

    program->bind();
    program->setUniformValue("MVP", projection * modelview);
    QColor rendercolor(opts.satsegmentcolor);
    QColor rendercolorsel(opts.satsegmentcolorsel);

    if((*seg).segmentselected)
        program->setUniformValue("outcolor", QVector4D(rendercolorsel.redF(), rendercolorsel.greenF(), rendercolorsel.blueF(), 1.0f));
    else
        program->setUniformValue("outcolor", QVector4D(rendercolor.redF(), rendercolor.greenF(), rendercolor.blueF(), 1.0f));

    QMatrix3x3 norm = modelview.normalMatrix();
    program->setUniformValue("NormalMatrix", norm);

    glDrawArrays(GL_LINE_LOOP, 0, nbrOfVertices - 10);
    glDrawArrays(GL_LINE_STRIP, nbrOfVertices - 10, 10);


    float mvmatrix[16], projmatrix[16];
    QMatrix4x4 MVP;
    MVP = projection * modelview;

    float *ptr = modelview.data();
    for(int i = 0; i < 16; i++)
        mvmatrix[i] = *(ptr + i);

    ptr = projection.data();
    for(int i = 0; i < 16; i++)
        projmatrix[i] = *(ptr + i);

    QVector2D win;

    LonLat2PointRad((float)seg->cornerpointfirst1.latitude, (float)seg->cornerpointfirst1.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend1 = win;

    LonLat2PointRad((float)seg->cornerpointfirst2.latitude, (float)seg->cornerpointfirst2.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend2 = win;

    LonLat2PointRad((float)seg->cornerpointlast1.latitude, (float)seg->cornerpointlast1.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend3 = win;

    LonLat2PointRad((float)seg->cornerpointlast2.latitude, (float)seg->cornerpointlast2.longitude, &vec, 1.0);
    win = glhProjectf (vec, mvmatrix, projmatrix, width, height);
    seg->winvecend4 = win;

    win = glhProjectf (seg->vec1, mvmatrix, projmatrix, width, height);
    seg->winvec1 = win;

    win = glhProjectf (seg->vec2, mvmatrix, projmatrix, width, height);
    seg->winvec2 = win;

}
Exemple #27
0
void OpenGLRenderer::render(GdvCanvas& canvas) {
    checkForErrors();
    if (isBlack) {
        glClearColor(0.0, 0.0, 0.0, 1.0);
    } else {
        glClearColor(1.0, 1.0, 1.0, 1.0);
    }
    // Rechnet auf die Projektionsmatrix die Kameramatrix und die Transformation drauf zum Rotieren
    QMatrix4x4 mvpMatrix = createProjectionMatrix() * createViewMatrix();

    // Mesh-Programm aktivieren
    glUseProgram(program_IDs[useMeshShader]);
    // Werte der Uniforms ändern
    glUniformMatrix4fv(mvpMatrix_ID, 1, false, mvpMatrix.data());
    glUniform1i(oiCheckIntersection_ID, isObjectIntersection);
    glUniform3f(oiSource_ID, (quelleX - 200)/100.0, (quelleY - 200)/100.0, 0);
    glUniform3f(oiObject_ID, (objectX - 200)/100.0, (objectY - 200)/100.0, 0);
    checkForErrors();
    if (isTransparency) {
        glUniform1f(discardRate_ID, (float) discardRate/100.0); // Fragment-Verwerfrate

        glBindVertexArray(0);
        // FBOs leeren
        glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glBindFramebuffer(GL_FRAMEBUFFER, fbo1);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glBindFramebuffer(GL_FRAMEBUFFER, fbo3);
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        int doubleSteps = 2 * steps;
        for (int i = 0; i < doubleSteps; i++) {
            //Wechseln der FBOs/Texturen
            GLuint newFBO, usedFBOTexture;
            if (i % 2 == 1){
                newFBO = fbo2;
                usedFBOTexture = colorTexture3;
            } else {
                newFBO = fbo3;
                usedFBOTexture = colorTexture2;
            }

            glUseProgram(program_IDs[useMeshShader]);

            float r;

            if (isFlimmern)
                r = (float) (std::rand() / (float) RAND_MAX);
            else
                r = i+1;

            glUniform1f(rand_ID, r);

            // FBO aktivieren
            glBindFramebuffer(GL_FRAMEBUFFER, fbo1);

            // Ausgabepuffer (Bildschirm/FBO) löschen
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            glUniform1i(meshTexture_ID, 0);
            glActiveTexture(GL_TEXTURE0 + 0);
            glBindTexture(GL_TEXTURE_2D, texture_ID);

            // Zeichnen
            glBindVertexArray(VAO_mesh);
            glDrawArrays(GL_TRIANGLES, 0, vertexCount_mesh);
            glBindVertexArray(0);

            // Addieren
            glBindFramebuffer(GL_FRAMEBUFFER, newFBO);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glUseProgram(program_IDs[useAddShader]);

            // setze Shadervariablen
            glUniform1i(pingPongStep_ID, i + 1);

            // jetzt beide Texturen ansprechen
            glUniform1i(newFBO_ID, 0); // 0 -> erste Textureinheit
            glUniform1i(oldFBO_ID, 1); // 1 -> zweite Textureinheit

            glActiveTexture(GL_TEXTURE0);
            glBindTexture(GL_TEXTURE_2D, colorTexture1);

            glActiveTexture(GL_TEXTURE1);
            glBindTexture(GL_TEXTURE_2D, usedFBOTexture);


            // Zeichnen
            glBindVertexArray(VAO_fbo);
            glDrawArrays(GL_TRIANGLES, 0, vertexCount_fbo);
            glBindVertexArray(0);

            checkForErrors();
        }
    } else {
        checkForErrors();
        // ohne Transparenz

        // in FBO rendern, damit ggfs. noch PostScreen-Effekte angewendet werden können
        glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
        // Ausgabepuffer (Bildschirm/FBO) löschen
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        glUseProgram(program_IDs[useMeshShader]);

        // Textur binden
        glUniform1i(meshTexture_ID, 0);
        glActiveTexture(GL_TEXTURE0);

        glBindTexture(GL_TEXTURE_2D, texture_ID);

        // keine Fragments discarden
        glUniform1f(discardRate_ID, 0.0f);



        // Zeichnen
        glBindVertexArray(VAO_mesh);
        glDrawArrays(GL_TRIANGLES, 0, vertexCount_mesh);
        glBindVertexArray(0);
        checkForErrors();

    }
    // PostScreen-Effekte hinzufügen

    if (isStarWars) {
        glBindFramebuffer(GL_FRAMEBUFFER, fbo1); // in FBO rendern
    } else {
        glBindFramebuffer(GL_FRAMEBUFFER, 0); // in Bildschirm rendern
    }

    glUseProgram(program_IDs[useFinalShader]); // Programm aktivieren

    // bools für finalShader setzen
    glUniform1i(sobel_ID, isSobel);
    glUniform1i(blue_ID, isBlue);
    glUniform1i(black_ID, isBlack);
    glUniform1f(height_ID, viewHeight);
    glUniform1f(width_ID, viewWidth);

    // Jetzt kann das FBO als Textur verwendet werden (Color−Attachment)
    glActiveTexture(GL_TEXTURE0 + 0);
    glBindTexture(GL_TEXTURE_2D, colorTexture2);
    if (isBlack) {
        glClearColor(0.0, 0.0, 0.0, 1.0);
    } else {
        glClearColor(1.0, 1.0, 1.0, 1.0);
    }
    // Ausgabepuffer (Bildschirm/FBO) löschen
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);


    // Zeichnen
    glBindVertexArray(VAO_fbo);
    glDrawArrays(GL_TRIANGLES, 0, vertexCount_fbo);
    glBindVertexArray(0);

    if (isStarWars) {
        glBindFramebuffer(GL_FRAMEBUFFER, 0);
        glUseProgram(program_IDs[useStarWarsShader]);
        glBindTexture(GL_TEXTURE_2D, colorTexture1);
        glUniform1f(swIntensity_ID, starwarsIntensity/100.0);
        glUniform1i(swThickness_ID, starwarsThickness);
        glUniform1i(swFrequency_ID, starwarsFrequency);
        glUniform1i(swViewWidth_ID, viewWidth);
        glUniform1i(swViewHeight_ID, viewHeight);
        float r = (float) (std::rand() / (float) RAND_MAX);
        if (!isStarWarsFlimmern) r = 0.5f;
        glUniform1f(swRandom_ID, truncf(r * 100.0) / 100.0);
        struct timeval tp;
        gettimeofday(&tp, NULL);
        long int ms = tp.tv_sec * 1000 + tp.tv_usec / 1000;
        glUniform1f(swTime_ID, ms);
        // Ausgabepuffer (Bildschirm/FBO) löschen
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // Zeichnen
        glBindVertexArray(VAO_fbo);
        glDrawArrays(GL_TRIANGLES, 0, vertexCount_fbo);
        glBindVertexArray(0);
    }

    // Textur und Programm deaktivieren
    glBindTexture(GL_TEXTURE_2D, 0);
    glUseProgram(0);

    checkForErrors();
}
Exemple #28
0
void Viewer::drawVisualHints()
{

    CGAL::QGLViewer::drawVisualHints();

    if(d->distance_is_displayed)
    {
        glDisable(GL_DEPTH_TEST);
        QMatrix4x4 mvpMatrix;
        double mat[16];
        camera()->getModelViewProjectionMatrix(mat);
        for(int i=0; i < 16; i++)
        {
          mvpMatrix.data()[i] = (float)mat[i];
        }
        if(!isOpenGL_4_3())
        {
          //draws the distance
          //nullifies the translation
          d->rendering_program_dist.bind();
          d->rendering_program_dist.setUniformValue("mvp_matrix", mvpMatrix);
          d->rendering_program_dist.setUniformValue("point_size", GLfloat(6.0f));
          d->vao.bind();
          glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(2));
          glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(2));
          d->vao.release();
          d->rendering_program_dist.release();
          glEnable(GL_DEPTH_TEST);
        }
        else
        {          
          QOpenGLShaderProgram* program = getShaderProgram(PROGRAM_SOLID_WIREFRAME);
          program->bind();
          QVector2D vp(width(), height());
          program->setUniformValue("viewport", vp);
          program->setUniformValue("near",(GLfloat)camera()->zNear());
          program->setUniformValue("far",(GLfloat)camera()->zFar());
          program->setUniformValue("width", GLfloat(3.0f));
          program->setAttributeValue("colors", QColor(Qt::black));
          program->setUniformValue("mvp_matrix", mvpMatrix);
          QMatrix4x4 f_mat;
          f_mat.setToIdentity();
          program->setUniformValue("f_matrix", f_mat);
          d->vao.bind();
          glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(2));
          d->vao.release();
          program->release();
          
          program = getShaderProgram(PROGRAM_NO_SELECTION);
          program->bind();
          program->setAttributeValue("colors", QColor(Qt::black));
          program->setAttributeValue("point_size", 6.0f);
          program->setUniformValue("mvp_matrix", mvpMatrix);
          program->setUniformValue("f_matrix", f_mat);
          d->vao.bind();
          glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(2));
          d->vao.release();
          program->release();
        }

    }
    if (!d->painter->isActive())
      d->painter->begin(this);
    //So that the text is drawn in front of everything
    d->painter->beginNativePainting();
    glDisable(GL_DEPTH_TEST);
    d->painter->endNativePainting();
    //Prints the displayMessage
    QFont font = QFont();
    QFontMetrics fm(font);
    TextItem *message_text = new TextItem(float(10 + fm.width(d->message)/2),
                                          float(height()-20),
                                          0, d->message, false,
                                          QFont(), Qt::gray );
    if (d->_displayMessage)
    {
      d->textRenderer->addText(message_text);
    }
    d->textRenderer->draw(this);
    
    if (d->_displayMessage)
      d->textRenderer->removeText(message_text);
}
Exemple #29
0
void Canvas::paintGL()
{
#ifndef NDEBUG
    logToFile("Painting started.");
#endif

    gl()->glClear(GL_COLOR_BUFFER_BIT);

    if (ready())
    {
        // Calculate the transformMatrix.
        double ratio = samplesRecorded/getInfoTable()->getVirtualWidth();

        QMatrix4x4 matrix;
        matrix.ortho(QRectF(getInfoTable()->getPosition()*ratio, 0, width()*ratio, height()));

        gl()->glUseProgram(signalProgram->getGLProgram());

        GLuint location = gl()->glGetUniformLocation(signalProgram->getGLProgram(), "transformMatrix");
        checkNotErrorCode(location, static_cast<GLuint>(-1), "glGetUniformLocation() failed.");
        gl()->glUniformMatrix4fv(location, 1, GL_FALSE, matrix.data());

        gl()->glUseProgram(eventProgram->getGLProgram());

        location = gl()->glGetUniformLocation(eventProgram->getGLProgram(), "transformMatrix");
        checkNotErrorCode(location, static_cast<GLuint>(-1), "glGetUniformLocation() failed.");
        gl()->glUniformMatrix4fv(location, 1, GL_FALSE, matrix.data());

        location = gl()->glGetUniformLocation(eventProgram->getGLProgram(), "divideBy");
        checkNotErrorCode(location, static_cast<GLuint>(-1), "glGetUniformLocation() failed.");
        gl()->glUniform1i(location, eventMode);

        location = gl()->glGetUniformLocation(eventProgram->getGLProgram(), "eventWidth");
        checkNotErrorCode(location, static_cast<GLuint>(-1), "glGetUniformLocation() failed.");
        gl()->glUniform1f(location, 0.45*height()/signalProcessor->getTrackCount());

        gl()->glUseProgram(rectangleLineProgram->getGLProgram());

        location = gl()->glGetUniformLocation(rectangleLineProgram->getGLProgram(), "transformMatrix");
        checkNotErrorCode(location, static_cast<GLuint>(-1), "glGetUniformLocation() failed.");
        gl()->glUniformMatrix4fv(location, 1, GL_FALSE, matrix.data());

        // Create the data block range needed.
        int firstSample = static_cast<unsigned int>(floor(getInfoTable()->getPosition()*ratio));
        int lastSample = static_cast<unsigned int>(ceil((getInfoTable()->getPosition() + width())*ratio));

        auto fromTo = DataFile::sampleRangeToBlockRange(make_pair(firstSample, lastSample), signalProcessor->getBlockSize());

        set<int> indexSet;

        for (int i = fromTo.first; i <= fromTo.second; ++i)
        {
            indexSet.insert(i);
        }

        // Get events.
        vector<tuple<int, int, int>> allChannelEvents;
        vector<tuple<int, int, int, int>> singleChannelEvents;
        currentEventTable()->getEventsForRendering(firstSample, lastSample, &allChannelEvents, &singleChannelEvents);

        // Draw.
        drawTimeLines();
        drawAllChannelEvents(allChannelEvents);

        while (indexSet.empty() == false)
        {
            SignalBlock block = signalProcessor->getAnyBlock(indexSet);

            drawSingleChannelEvents(block, singleChannelEvents);
            drawSignal(block);

            gl()->glFlush();

            indexSet.erase(block.getIndex());

            //logToFile("Block " << block.getIndex() << " painted.");
        }

        drawPositionIndicator();
        drawCross();

        glBindVertexArray(0);
    }

    gl()->glFinish();

    checkGLMessages();

#ifndef NDEBUG
    logToFile("Painting finished.");
#endif
}
Exemple #30
0
void Scene::draw(QGLViewer* viewer)
{       
    if(!are_buffers_initialized)
        initialize_buffers();
    QColor color;
    QMatrix4x4 fMatrix;
    fMatrix.setToIdentity();
    if(m_view_polyhedron && pos_poly.size()>0)
    {
        vao[2].bind();
        attrib_buffers(viewer);
        rendering_program.bind();
        color.setRgbF(0.0,0.0,0.0);
        rendering_program.setUniformValue(colorLocation, color);
        rendering_program.setUniformValue(fLocation, fMatrix);
        gl->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(pos_poly.size()/3));
        rendering_program.release();
        vao[2].release();
    }
    if(m_view_points && pos_points.size()>0)
    {
        gl->glPointSize(2.0f);
        vao[0].bind();
        attrib_buffers(viewer);
        rendering_program.bind();
        color.setRgbF(0.7,0.0,0.0);
        rendering_program.setUniformValue(colorLocation, color);
        rendering_program.setUniformValue(fLocation, fMatrix);
        gl->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(pos_points.size()/3));
        rendering_program.release();
        vao[0].release();
    }

    if(m_view_segments && pos_lines.size()>0)
    {
        vao[1].bind();
        attrib_buffers(viewer);
        rendering_program.bind();
        color.setRgbF(0.0,0.7,0.0);
        rendering_program.setUniformValue(colorLocation, color);
        rendering_program.setUniformValue(fLocation, fMatrix);
        gl->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(pos_lines.size()/3));
        rendering_program.release();
        vao[1].release();
    }
    if (m_view_plane && pos_plane.size()>0)
    {
        switch( m_cut_plane )
        {
        case UNSIGNED_EDGES:
        case UNSIGNED_FACETS:
        case SIGNED_FACETS:

            gl->glActiveTexture(GL_TEXTURE0);
            gl->glBindTexture(GL_TEXTURE_2D, textureId);

            for(int i=0; i< 16 ; i++)
                fMatrix.data()[i] =  m_frame->matrix()[i];
            vao[6].bind();
            attrib_buffers(viewer);
            tex_rendering_program.bind();
            tex_rendering_program.setUniformValue(tex_fLocation, fMatrix);

            gl->glDrawArrays(GL_TRIANGLES, 0,static_cast<GLsizei>(pos_plane.size()/3));
            tex_rendering_program.release();
            vao[6].release();
            break;

        case CUT_SEGMENTS:

            //cutting_segments
            fMatrix.setToIdentity();
            ::glLineWidth(2.0f);
            vao[3].bind();
            attrib_buffers(viewer);
            rendering_program.bind();
            color.setRgbF(1.0,0.0,0.0);
            rendering_program.setUniformValue(colorLocation, color);
            rendering_program.setUniformValue(fLocation, fMatrix);
            gl->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(pos_cut_segments.size()/3));
            ::glLineWidth(1.0f);
            rendering_program.release();
            vao[3].release();
            //grid
            for(int i=0; i< 16 ; i++)
                fMatrix.data()[i] =  m_frame->matrix()[i];
            vao[5].bind();
            attrib_buffers(viewer);
            rendering_program.bind();
            color.setRgbF(.6f, .6f, .6f);
            rendering_program.setUniformValue(colorLocation, color);
            rendering_program.setUniformValue(fLocation, fMatrix);
            gl->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(pos_grid.size()/3));
            rendering_program.release();
            vao[5].release();

            //cutting_plane
            // for(int i=0; i< 16 ; i++)
            //     fMatrix.data()[i] =  m_frame->matrix()[i];
            ::glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
            ::glEnable(GL_BLEND);
            vao[4].bind();
            attrib_buffers(viewer);
            rendering_program.bind();
            color.setRgbF(.6f, .85f, 1.f, .65f);
            rendering_program.setUniformValue(colorLocation, color);
            rendering_program.setUniformValue(fLocation, fMatrix);
            gl->glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_plane.size()/3));
            ::glDisable(GL_BLEND);
            rendering_program.release();
            vao[4].release();

            break;
        case NONE: // do nothing
            break;
        }
    }


}