31 auto count = mobject_->points().count() + 1;
32 std::vector<xcmath::vec3<_gl GLfloat>> vertices(count);
33 std::vector<xcmath::vec4<_gl GLfloat>> strokes_colors(count);
34 std::vector<xcmath::vec4<_gl GLfloat>> fill_colors(count);
35 for (
size_t i = 0; i < mobject_->points().count(); ++i) {
37 mobject_->points()[i].x(), mobject_->points()[i].y(), 0.0f);
42 mobject_->points()[0].x(), mobject_->points()[0].y(), 0.0f);
43 strokes_colors[count - 1] =
47 position_vbo_ =
GL::Buffer(_gl GL_ARRAY_BUFFER);
49 position_vbo_.buffer_data(vertices, _gl GL_STATIC_DRAW);
52 stroke_vbo_.buffer_data(strokes_colors, _gl GL_STATIC_DRAW);
55 fill_vbo_.buffer_data(fill_colors, _gl GL_STATIC_DRAW);
56 _gl glVertexAttribFormat(0, 3, _gl GL_FLOAT, _gl GL_FALSE, 0);
57 _gl glVertexAttribFormat(1, 4, _gl GL_FLOAT, _gl GL_FALSE, 0);
58 _gl glVertexAttribFormat(2, 4, _gl GL_FLOAT, _gl GL_FALSE, 0);
59 _gl glVertexAttribBinding(0, 0);
60 _gl glVertexAttribBinding(1, 1);
61 _gl glVertexAttribBinding(2, 2);
62 _gl glBindVertexBuffer(0, position_vbo_.id(), 0,
64 _gl glBindVertexBuffer(1, stroke_vbo_.id(), 0,
66 _gl glBindVertexBuffer(2, fill_vbo_.id(), 0,
68 _gl glEnableVertexAttribArray(0);
69 _gl glEnableVertexAttribArray(1);
70 _gl glEnableVertexAttribArray(2);
71 stroke_shader_program_ =
73 fill_shader_program_ =
88 if (mobject_->stroke_color().a() > 0.0f) {
89 stroke_shader_program_->use();
90 stroke_shader_program_->uniform(
"model", mobject_.model_matrix());
91 _gl glDrawArrays(_gl GL_LINE_STRIP, 0,
92 mobject_->points().closed()
93 ? (mobject_->points().count() + 1)
94 : mobject_->points().count());
96 if (mobject_->fill_color().a() > 0.0f) {
97 fill_shader_program_->use();
98 fill_shader_program_->uniform(
"model", mobject_.model_matrix());
99 _gl glDrawArrays(_gl GL_TRIANGLE_FAN, 0,
100 mobject_->points().count() + 1);