diff --git a/Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp b/Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp index fa68fd9795a..1031eecac74 100644 --- a/Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp +++ b/Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp @@ -85,27 +85,13 @@ Geodesic_arcs::Geodesic_arcs() cout << *it << endl; cout << "num points output = " << v.size() << endl; } - - - //const float c = 0.0; - //std::vector vertex_data { - // QVector3D(0,0,0), QVector3D(1,0,0), - // QVector3D(a,0,0), QVector3D(1,0,0), - - // QVector3D(0,0,0), QVector3D(0,1,0), - // QVector3D(0,a,0), QVector3D(0,1,0), - - // QVector3D(0,0,0), QVector3D(c,c,1), - // QVector3D(0,0,a), QVector3D(c,c,1) - //}; + std::vector vertex_data; - const QVector3D red(1, 0, 0); for (const auto& p : v) { const QVector3D arc_point(p.dx(), p.dy(), p.dz()); vertex_data.push_back(arc_point); - vertex_data.push_back(red); } m_num_arc_points = v.size(); // CAREFUL: not size of vertex_data!!! @@ -136,16 +122,16 @@ Geodesic_arcs::Geodesic_arcs() position_offset); glEnableVertexAttribArray(position_attrib_index); - // Color Vertex-Attribute - GLint color_attrib_index = 1; - auto* color_offset = reinterpret_cast(3 * sizeof(float)); - glVertexAttribPointer(color_attrib_index, - 3, - GL_FLOAT, - GL_FALSE, - stride, - color_offset); - glEnableVertexAttribArray(color_attrib_index); + //// Color Vertex-Attribute + //GLint color_attrib_index = 1; + //auto* color_offset = reinterpret_cast(3 * sizeof(float)); + //glVertexAttribPointer(color_attrib_index, + // 3, + // GL_FLOAT, + // GL_FALSE, + // stride, + // color_offset); + //glEnableVertexAttribArray(color_attrib_index); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindVertexArray(0); diff --git a/Arrangement_on_surface_2/demo/earth/mainwidget.cpp b/Arrangement_on_surface_2/demo/earth/mainwidget.cpp index 20086bfc796..2bf065eae0b 100644 --- a/Arrangement_on_surface_2/demo/earth/mainwidget.cpp +++ b/Arrangement_on_surface_2/demo/earth/mainwidget.cpp @@ -116,6 +116,7 @@ void MainWidget::init_shader_programs() { init_sp_smooth(); init_sp_per_vertex_color(); + init_sp_arc(); } void MainWidget::init_sp_smooth() { @@ -130,6 +131,12 @@ void MainWidget::init_sp_per_vertex_color() const char* fs = "shaders/color_only_fs.glsl"; m_sp_per_vertex_color.init(vs, "", fs); } +void MainWidget::init_sp_arc() +{ + const char* vs = "shaders/arc_vs.glsl"; + const char* fs = "shaders/arc_fs.glsl"; + m_sp_arc.init(vs, "", fs); +} std::ostream& operator << (std::ostream& os, const QVector4D& v) @@ -183,7 +190,7 @@ void MainWidget::paintGL() { glDisable(GL_DEPTH_TEST); - auto& sp = m_sp_per_vertex_color; + auto& sp = m_sp_arc; sp.use(); sp.set_uniform("u_mvp", mvp); @@ -196,6 +203,8 @@ void MainWidget::paintGL() const auto cos_beta = sin_alpha; const auto p = (r * cos_beta) * n; QVector4D plane(n.x(), n.y(), n.z(), -QVector3D::dotProduct(p, n)); + const QVector4D red(1, 0, 0, 1); + sp.set_uniform("u_color", red); sp.set_uniform("u_plane", plane); m_geodesic_arcs->draw(); diff --git a/Arrangement_on_surface_2/demo/earth/mainwidget.h b/Arrangement_on_surface_2/demo/earth/mainwidget.h index 208f14e8c27..0ed2b768563 100644 --- a/Arrangement_on_surface_2/demo/earth/mainwidget.h +++ b/Arrangement_on_surface_2/demo/earth/mainwidget.h @@ -47,6 +47,7 @@ class MainWidget : public QOpenGLWidget, protected OpenGLFunctionsBase void init_shader_programs(); void init_sp_smooth(); void init_sp_per_vertex_color(); + void init_sp_arc(); private: // Objects in the scene diff --git a/Arrangement_on_surface_2/demo/earth/shaders/arc_fs.glsl b/Arrangement_on_surface_2/demo/earth/shaders/arc_fs.glsl index 8f42e2c2150..216de00c8d3 100644 --- a/Arrangement_on_surface_2/demo/earth/shaders/arc_fs.glsl +++ b/Arrangement_on_surface_2/demo/earth/shaders/arc_fs.glsl @@ -1,7 +1,7 @@ #version 330 -uniform vec3 u_color; +uniform vec4 u_color; uniform vec4 u_plane; @@ -14,5 +14,5 @@ void main() if( dot(u_plane, vec4(v_pos, 1)) < 0 ) discard; - out_color = vec4(u_color, 1); + out_color = u_color; } \ No newline at end of file