Esempio n. 1
0
void Scene_c3t3_item::draw_points(CGAL::Three::Viewer_interface * viewer) const
{
  if (!are_buffers_filled)
  {
    compute_elements();
    initialize_buffers(viewer);
  }
  vaos[Edges]->bind();
  program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
  attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
  program->bind();
  program->setAttributeValue("colors", this->color());
  viewer->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(positions_lines.size() / 3));
  vaos[Edges]->release();
  program->release();

  vaos[2]->bind();
  program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
  attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
  program->bind();
  program->setAttributeValue("colors", this->color());
  QMatrix4x4 f_mat;
  for (int i = 0; i<16; i++)
    f_mat.data()[i] = frame->matrix()[i];
  program->setUniformValue("f_matrix", f_mat);
  viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_grid.size() / 3));
  program->release();
  vaos[2]->release();
}
Esempio n. 2
0
// Wireframe OpenGL drawing
void 
Scene_polylines_item::draw_edges(Viewer_interface* viewer) const {
    if(!are_buffers_filled)
    {
        compute_elements();
        initialize_buffers(viewer);
    }

    vaos[0]->bind();
    attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
    program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
    program->bind();
    program->setAttributeValue("colors", this->color());
    viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(nb_lines/4));
    program->release();
    vaos[0]->release();
    if(d->draw_extremities)
    {
        if(viewer->extension_is_found)
        {
            vaos[2]->bind();
            attrib_buffers(viewer, PROGRAM_INSTANCED_WIRE);
            program = getShaderProgram(PROGRAM_INSTANCED_WIRE);
            program->bind();
            viewer->glDrawArraysInstanced(GL_LINES, 0,
                                          static_cast<GLsizei>(nb_wire/3), nbSpheres);
            program->release();
            vaos[2]->release();
        }
    }

}
Esempio n. 3
0
void
Viewer::draw()
{
    if(!are_buffers_initialized)
        initialize_buffers();
    QColor color;
    //points
    vao[1].bind();
    attrib_buffers(this);
    rendering_program_points.bind();
    color.setRgbF(1.0f, 0.0f, 0.0f);
    glPointSize(5);
    ::glEnable(GL_POINT_SMOOTH);
    rendering_program_points.setUniformValue(colorLocation_points, color);
    glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(pos_points.size()/3));
    rendering_program_points.release();
    vao[1].release();
    //facets
    vao[0].bind();
    attrib_buffers(this);
    rendering_program.bind();
    color.setRgbF(0.5f, 1.0f, 0.5f);
    rendering_program.setUniformValue(colorLocation, color);
    glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_poly.size()/3));
    rendering_program.release();
    vao[0].release();

}
Esempio n. 4
0
// Wireframe OpenGL drawing
void 
Scene_polylines_item::draw_edges(Viewer_interface* viewer) const {

    if(!are_buffers_filled)
        initialize_buffers(viewer);

    vaos[0]->bind();
    attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
    program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
    program->bind();
    QColor temp = this->color();
    program->setAttributeValue("colors", temp);
    qFunc.glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines.size()/4));
    program->release();
    vaos[0]->release();
    if(d->draw_extremities)
    {
        vaos[2]->bind();
        attrib_buffers(viewer, PROGRAM_INSTANCED_WIRE);
        program = getShaderProgram(PROGRAM_INSTANCED_WIRE);
        program->bind();
        qFunc.glDrawArraysInstanced(GL_LINES, 0,
                                    static_cast<GLsizei>(positions_wire_spheres.size()/4), nbSpheres);
        program->release();
        vaos[2]->release();
    }

}
Esempio n. 5
0
// Shaded OpenGL drawing: only draw spheres
void
Scene_polylines_item::draw(Viewer_interface* viewer) const {

    if(!are_buffers_filled)
        initialize_buffers(viewer);
    if(d->draw_extremities)
    {
        if(viewer->extension_is_found)
        {
            vaos[1]->bind();
            program = getShaderProgram(PROGRAM_INSTANCED);
            attrib_buffers(viewer, PROGRAM_INSTANCED);
            program->bind();
            viewer->glDrawArraysInstanced(GL_TRIANGLES, 0,
                                          static_cast<GLsizei>(nb_spheres/3), nbSpheres);
            program->release();
            vaos[1]->release();
        }
        else
        {
            vaos[1]->bind();
            program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
            attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
            glPointSize(8.0f);
            glEnable(GL_POINT_SMOOTH);
            program->bind();
            viewer->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(nb_centers/3));
            glDisable(GL_POINT_SMOOTH);
            program->release();
            vaos[1]->release();
        }
    }
}
Esempio n. 6
0
void Viewer::draw()
{
  if(scene)
  {
    glEnable(GL_DEPTH_TEST);
    if(!are_buffers_initialized)
      initialize_buffers();

    QColor color;
    if ( !wireframe )
    {
      if(flatShading)
      {
        vao[0].bind();
        attrib_buffers(this);
        rendering_program.bind();
        glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_facets.size()/3));
        rendering_program.release();
        vao[0].release();
      }
      else
      {
        vao[1].bind();
        attrib_buffers(this);
        rendering_program.bind();
        glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_facets.size()/3));
        rendering_program.release();
        vao[1].release();
      }
    }
    if(edges)
    {
      vao[2].bind();
      attrib_buffers(this);
      color.setRgbF(0.2f, 0.2f, 0.7f);
      rendering_program_p_l.bind();
      rendering_program_p_l.setAttributeValue(colorLocation,color);
      glLineWidth(size_edges);
      glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(pos_lines.size()/3));
      rendering_program_p_l.release();
      vao[2].release();
    }
    if(vertices)
    {
      vao[3].bind();
      attrib_buffers(this);
      color.setRgbF(.2f,.2f,.6f);
      rendering_program_p_l.bind();
      rendering_program_p_l.setAttributeValue(colorLocation,color);
      rendering_program_p_l.setUniformValue("point_size", GLfloat(size_points));
      glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(pos_points.size()/3));
      rendering_program_p_l.release();
      vao[3].release();
    }
  }
}
Esempio n. 7
0
void Viewer::draw()
{
if(!are_buffers_initialized)
    initialize_buffers();


QColor color;
    if ( !wireframe )
    {
      if(flatShading)
      {

          vao[0].bind();
          attrib_buffers(this);
          rendering_program.bind();
          glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_facets.size()/3));
          rendering_program.release();
          vao[0].release();
      }
      else
      {
          vao[1].bind();
          attrib_buffers(this);
          rendering_program.bind();
          glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(pos_facets.size()/3));
          rendering_program.release();
          vao[1].release();
      }
    }
    if(edges)
    {
        vao[2].bind();
        attrib_buffers(this);
        color.setRgbF(0.2f, 0.2f, 0.7f);
        rendering_program_p_l.bind();
        rendering_program_p_l.setAttributeValue(colorLocation,color);
        glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(pos_lines.size()/3));
        rendering_program_p_l.release();
        vao[2].release();
    }
    if(vertices)
    {
        ::glPointSize(7.f);
        vao[3].bind();
        attrib_buffers(this);
        color.setRgbF(.2f,.2f,.6f);
        rendering_program_p_l.bind();
        rendering_program_p_l.setAttributeValue(colorLocation,color);
        glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(pos_points.size()/3));
        rendering_program_p_l.release();
        vao[3].release();
    }
}
void Scene_polyhedron_selection_item::draw(Viewer_interface* viewer) const
{

    if(!are_buffers_filled)
        initialize_buffers(viewer);

    draw_points(viewer);
    GLfloat offset_factor;
    GLfloat offset_units;
    viewer->glGetFloatv( GL_POLYGON_OFFSET_FACTOR, &offset_factor);
    viewer->glGetFloatv(GL_POLYGON_OFFSET_UNITS, &offset_units);
    glPolygonOffset(-1.f, 1.f);

    vaos[0]->bind();
    program = getShaderProgram(PROGRAM_WITH_LIGHT);
    attrib_buffers(viewer,PROGRAM_WITH_LIGHT);
    program->bind();
    program->setAttributeValue("colors",facet_color);
    viewer->glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(nb_facets/3));
    program->release();
    vaos[0]->release();
    glPolygonOffset(offset_factor, offset_units);
    draw_edges(viewer);


}
void
Scene_implicit_function_item::draw(Viewer* viewer) const
{
  if(!texture_initialized)
  {
    viewer->glGenTextures(1, &textureId);
    texture_initialized = true;
  }
  if(!are_buffers_initialized)
    initialize_buffers(viewer);
  QColor color;
  vao[0].bind();
  attrib_buffers(viewer);
  rendering_program.bind();
  color.setRgbF(0.0,0.0,0.0);
  rendering_program.setUniformValue(colorLocation[0], color);
  glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(v_cube.size()/3));
  rendering_program.release();
  vao[0].release();

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

  vao[1].bind();
  tex_rendering_program.bind();
  glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(v_plan.size()/3));
  tex_rendering_program.release();
  vao[1].release();

}
Esempio n. 10
0
void
Viewer::draw()
{
    glEnable(GL_DEPTH_TEST);
  if(!are_buffers_initialized)
      initialize_buffers();
  QColor color;
 //the points
  glEnable(GL_BLEND);
  glEnable(GL_POINT_SMOOTH);
  glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
  glEnable(GL_LINE_SMOOTH);
  glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_POLYGON_OFFSET_FILL);
  glPolygonOffset(3.0f,-3.0f);


  attrib_buffers(this);
  vao[0].bind();
  color.setRgbF(1.0f, 0.72f, 0.06f);
  rendering_program.bind();
  rendering_program.setUniformValue(colorLocation[0], color);
  glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(pos_points.size()/3));
  rendering_program.release();
  vao[0].release();

  //The Lines
  glDisable(GL_POLYGON_OFFSET_FILL);

  vao[1].bind();
  color.setRgbF(0.27f, 0.51f, 0.7f);
  rendering_program.bind();
  rendering_program.setUniformValue(colorLocation[0], color);
  glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(pos_lines.size()/3));
  rendering_program.release();
  vao[1].release();

  if (scene->eight_copies) {
      vao[2].bind();
      color.setRgbF(0.69f, 0.77f, 0.87f);
      rendering_program.bind();
      rendering_program.setUniformValue(colorLocation[0], color);
      glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(pos_8lines2D.size()/3));
      rendering_program.release();
      vao[2].release();


      if (!scene->two_dimensional) {
          vao[3].bind();
          color.setRgbF(0.69f, 0.77f, 0.87f);
          rendering_program.bind();
          rendering_program.setUniformValue(colorLocation[0], color);
          glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(pos_8lines.size()/3));
          rendering_program.release();
          vao[3].release();
      }
  }
}
Esempio n. 11
0
void Scene_c3t3_item::draw(CGAL::Three::Viewer_interface* viewer) const {
  if (!are_buffers_filled)
  {
    compute_elements();
    initialize_buffers(viewer);
  }
  vaos[Facets]->bind();
  program = getShaderProgram(PROGRAM_WITH_LIGHT);
  attrib_buffers(viewer, PROGRAM_WITH_LIGHT);
  program->bind();
  //program->setAttributeValue("colors", this->color());
  viewer->glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(positions_poly.size() / 3));
  program->release();
  vaos[Facets]->release();

  if(spheres_are_shown)
  {
    vaos[Spheres]->bind();
    program_sphere->bind();
    //ModelViewMatrix used for the transformation of the camera.
    QMatrix4x4 mvp_mat;
    // ModelView Matrix used for the lighting system
    QMatrix4x4 mv_mat;
    GLdouble d_mat[16];
    GLint is_both_sides = 0;
    viewer->camera()->getModelViewProjectionMatrix(d_mat);
    //Convert the GLdoubles matrices in GLfloats
    for (int i=0; i<16; ++i){
      mvp_mat.data()[i] = GLfloat(d_mat[i]);
    }
    viewer->camera()->getModelViewMatrix(d_mat);
    for (int i=0; i<16; ++i)
      mv_mat.data()[i] = GLfloat(d_mat[i]);
    QVector4D position(0.0f,0.0f,1.0f, 1.0f );
    QVector4D ambient(0.4f, 0.4f, 0.4f, 0.4f);
    // Diffuse
    QVector4D diffuse(1.0f, 1.0f, 1.0f, 1.0f);
    // Specular
    QVector4D specular(0.0f, 0.0f, 0.0f, 1.0f);
    viewer->glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &is_both_sides);


    program_sphere->setUniformValue("mvp_matrix", mvp_mat);
    program_sphere->setUniformValue("mv_matrix", mv_mat);
    program_sphere->setUniformValue("light_pos", position);
    program_sphere->setUniformValue("light_diff",diffuse);
    program_sphere->setUniformValue("light_spec", specular);
    program_sphere->setUniformValue("light_amb", ambient);
    program_sphere->setUniformValue("spec_power", 51.8f);
    program_sphere->setUniformValue("is_two_side", is_both_sides);

    viewer->glDrawArraysInstanced(GL_TRIANGLES, 0,
                                  static_cast<GLsizei>(s_vertex.size()/3),
                                  static_cast<GLsizei>(s_radius.size()));
    program_sphere->release();
    vaos[Spheres]->release();
  }
}
    void draw(Viewer_interface* viewer) const {
        if(!are_buffers_filled)
            initialize_buffers(viewer);
        vaos[0]->bind();
        program = getShaderProgram(PROGRAM_WITH_LIGHT);
        attrib_buffers(viewer, PROGRAM_WITH_LIGHT);
        program->bind();
        viewer->glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(positions_poly.size()/3));
        program->release();
        vaos[0]->release();


    }
void Scene_polyhedron_selection_item::draw_edges(Viewer_interface* viewer) const
{

    viewer->glLineWidth(3.f);
    vaos[1]->bind();
    program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
    attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT);
    program->bind();
    program->setAttributeValue("colors",edge_color);
    viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(nb_lines/3));
    program->release();
    vaos[1]->release();
    viewer->glLineWidth(1.f);
}
void Scene_polyhedron_selection_item::draw_points(Viewer_interface* viewer) const
{
    viewer->glPointSize(5.f);
    vaos[2]->bind();
    program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
    attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT);
    program->bind();
    program->setAttributeValue("colors",vertex_color);
    viewer->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(nb_points/3));
    program->release();
    vaos[2]->release();
    viewer->glPointSize(1.f);

}
Esempio n. 15
0
void 
Scene_polylines_item::draw_points(Viewer_interface* viewer) const {
    if(!are_buffers_filled)
        initialize_buffers(viewer);

    vaos[0]->bind();
    attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
    program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
    program->bind();
    qFunc.glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(positions_lines.size()/4));
    // Clean-up
   vaos[0]->release();
   program->release();
}
void Scene_polyhedron_shortest_path_item::draw_points(Viewer_interface* viewer) const
{
    if(!are_buffers_filled)
    {
        initialize_buffers(viewer);
    }
   program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
   attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
   vaos[0]->bind();
   program->bind();
   program->setAttributeValue("colors", QColor(Qt::green));
   viewer->glDrawArrays(GL_POINTS, 0, vertices.size()/3);
   program->release();
   vaos[0]->release();
}
    void draw_points(Viewer_interface * viewer) const
    {
        if(!are_buffers_filled)
            initialize_buffers(viewer);
        vaos[1]->bind();
        program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
        attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
        program->bind();
        viewer->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(positions_lines.size()/3));
       vaos[1]->release();
       program->release();

       vaos[2]->bind();
       program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
       attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
       program->bind();
       QMatrix4x4 f_mat;
       for(int i=0; i<16; i++)
           f_mat.data()[i]=frame->matrix()[i];
       program->setUniformValue("f_matrix",f_mat);
       viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_grid.size()/3));
       program->release();
       vaos[2]->release();
    }
void Scene_textured_polyhedron_item::draw_edges(Viewer_interface* viewer) const {
    if(!are_buffers_filled)
        initialize_buffers(viewer);

    vaos[1]->bind();
    qFunc.glActiveTexture(GL_TEXTURE0);
    qFunc.glBindTexture(GL_TEXTURE_2D, textureId);
    attrib_buffers(viewer, PROGRAM_WITH_TEXTURED_EDGES);

    program=getShaderProgram(PROGRAM_WITH_TEXTURED_EDGES);
    program->bind();
    qFunc.glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines.size()/4));
    //Clean-up
    program->release();
    vaos[1]->release();
}
Esempio n. 19
0
void 
Scene_polylines_item::draw_points(Viewer_interface* viewer) const {
    if(!are_buffers_filled)
        initialize_buffers(viewer);

    vaos[0]->bind();
    attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
    program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
    program->bind();
    QColor temp = this->color();
    program->setAttributeValue("colors", temp);
    viewer->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(nb_lines/4));
    // Clean-up
   vaos[0]->release();
   program->release();
}
// Points/Wireframe/Flat/Gouraud OpenGL drawing in a display list
void Scene_textured_polyhedron_item::draw(Viewer_interface* viewer) const {

    if(!are_buffers_filled)
        initialize_buffers(viewer);

    vaos[0]->bind();
    viewer->glActiveTexture(GL_TEXTURE0);
    viewer->glBindTexture(GL_TEXTURE_2D, textureId);
    attrib_buffers(viewer, PROGRAM_WITH_TEXTURE);
    program=getShaderProgram(PROGRAM_WITH_TEXTURE);
    program->bind();
    viewer->glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(nb_facets/4));
    //Clean-up
    program->release();
    vaos[0]->release();
}
Esempio n. 21
0
 void Scene_combinatorial_map_item::draw_points(CGAL::Three::Viewer_interface* viewer) const
{
     if(!are_buffers_filled)
     {
         compute_elements();
         initialize_buffers(viewer);
     }
     vaos[Points]->bind();
     program=getShaderProgram(PROGRAM_WITHOUT_LIGHT);
     attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT);
     program->bind();
     program->setAttributeValue("colors", this->color());
     viewer->glDrawArrays(GL_POINTS, 0, static_cast<GLsizei>(nb_points/3));
     vaos[Points]->release();
     program->release();

}
Esempio n. 22
0
// Shaded OpenGL drawing: only draw spheres
void
Scene_polylines_item::draw(Viewer_interface* viewer) const {

    if(!are_buffers_filled)
        initialize_buffers(viewer);
    if(d->draw_extremities)
    {
        vaos[1]->bind();
        program = getShaderProgram(PROGRAM_INSTANCED);
        attrib_buffers(viewer, PROGRAM_INSTANCED);
        program->bind();
        qFunc.glDrawArraysInstanced(GL_TRIANGLES, 0,
                                    static_cast<GLsizei>(positions_spheres.size()/4), nbSpheres);
        program->release();
        vaos[1]->release();
    }
}
Esempio n. 23
0
void Scene_plane_item::draw_edges(Viewer_interface* viewer)const
{
    if(!are_buffers_filled)
        initialize_buffers(viewer);
    vaos[1]->bind();
    program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
    attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
    QMatrix4x4 f_matrix;
    for(int i=0; i<16; i++)
        f_matrix.data()[i] = (float)frame->matrix()[i];
    program->bind();
    program->setUniformValue("f_matrix", f_matrix);
    program->setAttributeValue("colors",QVector3D(0,0,0));
    viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines.size()/3));
    program->release();
    vaos[1]->release();
}
void Scene_polyhedron_transform_item::draw_edges(Viewer_interface* viewer) const
{
    if(!are_buffers_filled)
        initialize_buffers(viewer);
    vaos[0]->bind();
    program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
    attrib_buffers(viewer,PROGRAM_WITHOUT_LIGHT);
    program->bind();
    QMatrix4x4 f_matrix;
    for (int i=0; i<16; ++i){
        f_matrix.data()[i] = (float)frame->matrix()[i];
    }
    program->setUniformValue("f_matrix", f_matrix);
    viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(nb_lines/3));
    vaos[0]->release();
    program->release();

}
Esempio n. 25
0
void Scene_c3t3_item::draw(CGAL::Three::Viewer_interface* viewer) const {
  Scene_c3t3_item* ncthis = const_cast<Scene_c3t3_item*>(this);

  if (!are_buffers_filled)
  {
    ncthis->compute_elements();
    ncthis->initialize_buffers(viewer);
  }

  vaos[Grid]->bind();
  program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
  attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
  program->bind();
  program->setAttributeValue("colors", QColor(Qt::black));
  QMatrix4x4 f_mat;
  for (int i = 0; i<16; i++)
    f_mat.data()[i] = frame->matrix()[i];
  program->setUniformValue("f_matrix", f_mat);
  viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_grid.size() / 3));
  program->release();
  vaos[Grid]->release();

  vaos[Facets]->bind();
  program = getShaderProgram(PROGRAM_C3T3);
  attrib_buffers(viewer, PROGRAM_C3T3);
  program->bind();
  QVector4D cp(this->plane().a(),this->plane().b(),this->plane().c(),this->plane().d());
  program->setUniformValue("cutplane", cp);
  // positions_poly_size is the number of total facets in the C3T3
  // it is only computed once and positions_poly is emptied at the end
  viewer->glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(positions_poly_size / 3));
  program->release();
  vaos[Facets]->release();


  if(!frame->isManipulated()) {
    if (!are_intersection_buffers_filled)
    {
      ncthis->compute_intersections();
      ncthis->initialize_intersection_buffers(viewer);
    }
    vaos[iFacets]->bind();
    program = getShaderProgram(PROGRAM_WITH_LIGHT);
    attrib_buffers(viewer, PROGRAM_WITH_LIGHT);
    program->bind();

    // positions_poly is also used for the faces in the cut plane
    // and changes when the cut plane is moved
    viewer->glDrawArrays(GL_TRIANGLES, 0, static_cast<GLsizei>(positions_poly.size() / 3));
    program->release();
    vaos[iFacets]->release();
  }

  if(spheres_are_shown)
  {
    vaos[Spheres]->bind();
    program_sphere->bind();
    //ModelViewMatrix used for the transformation of the camera.
    QMatrix4x4 mvp_mat;
    // ModelView Matrix used for the lighting system
    QMatrix4x4 mv_mat;
    GLdouble d_mat[16];
    GLint is_both_sides = 0;
    viewer->camera()->getModelViewProjectionMatrix(d_mat);
    //Convert the GLdoubles matrices in GLfloats
    for (int i=0; i<16; ++i){
      mvp_mat.data()[i] = GLfloat(d_mat[i]);
    }
    viewer->camera()->getModelViewMatrix(d_mat);
    for (int i=0; i<16; ++i)
      mv_mat.data()[i] = GLfloat(d_mat[i]);
    QVector4D position(0.0f,0.0f,1.0f, 1.0f );
    QVector4D ambient(0.4f, 0.4f, 0.4f, 0.4f);
    // Diffuse
    QVector4D diffuse(1.0f, 1.0f, 1.0f, 1.0f);
    // Specular
    QVector4D specular(0.0f, 0.0f, 0.0f, 1.0f);
    viewer->glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &is_both_sides);

    QVector4D cp(this->plane().a(),this->plane().b(),this->plane().c(),this->plane().d());

    program_sphere->setUniformValue("cutplane", cp);
    program_sphere->setUniformValue("mvp_matrix", mvp_mat);
    program_sphere->setUniformValue("mv_matrix", mv_mat);
    program_sphere->setUniformValue("light_pos", position);
    program_sphere->setUniformValue("light_diff",diffuse);
    program_sphere->setUniformValue("light_spec", specular);
    program_sphere->setUniformValue("light_amb", ambient);
    program_sphere->setUniformValue("spec_power", 51.8f);
    program_sphere->setUniformValue("is_two_side", is_both_sides);

    viewer->glDrawArraysInstanced(GL_TRIANGLES, 0,
                                  static_cast<GLsizei>(s_vertex.size()/3),
                                  static_cast<GLsizei>(s_radius.size()));
    program_sphere->release();
    vaos[Spheres]->release();
  }
}
Esempio n. 26
0
void Scene_c3t3_item::draw_edges(CGAL::Three::Viewer_interface* viewer) const {
  if(renderingMode() == FlatPlusEdges)
  {
    GLint renderMode;
    glGetIntegerv(GL_RENDER_MODE, &renderMode);
    if(renderMode == GL_SELECT) return;
  }
  Scene_c3t3_item* ncthis = const_cast<Scene_c3t3_item*>(this);
  if (!are_buffers_filled)
  {
    ncthis->compute_elements();
    ncthis->initialize_buffers(viewer);
  }

  if(renderingMode() == Wireframe)
  {
    vaos[Grid]->bind();
    program = getShaderProgram(PROGRAM_WITHOUT_LIGHT);
    attrib_buffers(viewer, PROGRAM_WITHOUT_LIGHT);
    program->bind();
    program->setAttributeValue("colors", QColor(Qt::black));
    QMatrix4x4 f_mat;
    for (int i = 0; i<16; i++)
        f_mat.data()[i] = frame->matrix()[i];
    program->setUniformValue("f_matrix", f_mat);
    viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_grid.size() / 3));
    program->release();
    vaos[Grid]->release();
  }
  vaos[Edges]->bind();
  program = getShaderProgram(PROGRAM_C3T3_EDGES);
  attrib_buffers(viewer, PROGRAM_C3T3_EDGES);
  program->bind();
  QVector4D cp(this->plane().a(),this->plane().b(),this->plane().c(),this->plane().d());
  program->setUniformValue("cutplane", cp);
  program->setAttributeValue("colors", QColor(Qt::black));
  viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines_size / 3));
  program->release();
  vaos[Edges]->release();

  if(!frame->isManipulated()) {
    if (!are_intersection_buffers_filled)
    {
      ncthis->compute_intersections();
      ncthis->initialize_intersection_buffers(viewer);
    }
    vaos[iEdges]->bind();
    program = getShaderProgram(PROGRAM_NO_SELECTION);
    attrib_buffers(viewer, PROGRAM_NO_SELECTION);
    program->bind();
    program->setAttributeValue("colors", QColor(Qt::black));
    viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(positions_lines.size() / 3));
    program->release();
    vaos[iEdges]->release();
  }

  if(spheres_are_shown)
  {
      vaos[Wired_spheres]->bind();
      program_sphere->bind();
      //ModelViewMatrix used for the transformation of the camera.
      QMatrix4x4 mvp_mat;
      // ModelView Matrix used for the lighting system
      QMatrix4x4 mv_mat;
      GLdouble d_mat[16];
      GLint is_both_sides = 0;
      viewer->camera()->getModelViewProjectionMatrix(d_mat);
      //Convert the GLdoubles matrices in GLfloats
      for (int i=0; i<16; ++i){
          mvp_mat.data()[i] = GLfloat(d_mat[i]);
      }
      viewer->camera()->getModelViewMatrix(d_mat);
      for (int i=0; i<16; ++i)
          mv_mat.data()[i] = GLfloat(d_mat[i]);
      QVector4D position(0.0f,0.0f,1.0f, 1.0f );
      QVector4D ambient(0.4f, 0.4f, 0.4f, 0.4f);
      // Diffuse
      QVector4D diffuse(1.0f, 1.0f, 1.0f, 1.0f);
      // Specular
      QVector4D specular(0.0f, 0.0f, 0.0f, 1.0f);
      viewer->glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &is_both_sides);


      program_sphere->setUniformValue("mvp_matrix", mvp_mat);
      program_sphere->setUniformValue("mv_matrix", mv_mat);
      program_sphere->setUniformValue("light_pos", position);
      program_sphere->setUniformValue("light_diff",diffuse);
      program_sphere->setUniformValue("light_spec", specular);
      program_sphere->setUniformValue("light_amb", ambient);
      program_sphere->setUniformValue("spec_power", 51.8f);
      program_sphere->setUniformValue("is_two_side", is_both_sides);

      viewer->glDrawArraysInstanced(GL_TRIANGLES, 0,
                                    static_cast<GLsizei>(ws_vertex.size()/3),
                                    static_cast<GLsizei>(s_radius.size()));
      program_sphere->release();
      vaos[Wired_spheres]->release();
  }
}
void Volume_plane_intersection::draw(Viewer* viewer) const {
  viewer->glLineWidth(4.0f);
  attrib_buffers(viewer);
  if(b && c) {

    vao[0].bind();
    rendering_program.bind();
    GLdouble mat[16];
    b->manipulatedFrame()->getMatrix(mat);
    QMatrix4x4 b_mat, c_mat;
    for(int i=0; i<16; i++)
    {
       b_mat.data()[i] = (float)mat[i];
    }
    c->manipulatedFrame()->getMatrix(mat);
    for(int i=0; i<16; i++)
    {
       c_mat.data()[i] = (float)mat[i];
    }
    rendering_program.setUniformValue("f_matrix", b_mat*c_mat);
    viewer->glDrawArrays(GL_LINES, 0, 2);
    rendering_program.release();
    vao[0].release();
  }

  if(a && c) {
      vao[1].bind();
      rendering_program.bind();
      GLdouble mat[16];
      a->manipulatedFrame()->getMatrix(mat);
      QMatrix4x4 a_mat, c_mat;
      for(int i=0; i<16; i++)
      {
         a_mat.data()[i] = (float)mat[i];
      }
      c->manipulatedFrame()->getMatrix(mat);
      for(int i=0; i<16; i++)
      {
         c_mat.data()[i] = (float)mat[i];
      }
      rendering_program.setUniformValue("f_matrix", a_mat*c_mat);
      viewer->glDrawArrays(GL_LINES, 0, 2);
      rendering_program.release();
      vao[1].release();
  }

  if(a && b) {
      vao[2].bind();
      rendering_program.bind();
      GLdouble mat[16];
      a->manipulatedFrame()->getMatrix(mat);
      QMatrix4x4 a_mat, b_mat;
      for(int i=0; i<16; i++)
      {
         a_mat.data()[i] = (float)mat[i];
      }
      b->manipulatedFrame()->getMatrix(mat);
      for(int i=0; i<16; i++)
      {
         b_mat.data()[i] = (float)mat[i];
      }
      rendering_program.setUniformValue("f_matrix", a_mat*b_mat);
      viewer->glDrawArrays(GL_LINES, 0, 2);
      rendering_program.release();
      vao[2].release();
  }

  viewer->glLineWidth(1.0f);
}
Esempio n. 28
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;
        }
    }


}