Skip to content

Commit

Permalink
Bug fix: arc-shader initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
denizdiktas committed Jun 15, 2023
1 parent d3dc562 commit f8ccbb1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
36 changes: 11 additions & 25 deletions Arrangement_on_surface_2/demo/earth/Geodesic_arcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QVector3D> 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<QVector3D> 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!!!

Expand Down Expand Up @@ -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<const void*>(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<const void*>(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);
Expand Down
11 changes: 10 additions & 1 deletion Arrangement_on_surface_2/demo/earth/mainwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -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)
Expand Down Expand Up @@ -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);

Expand All @@ -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();

Expand Down
1 change: 1 addition & 0 deletions Arrangement_on_surface_2/demo/earth/mainwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Arrangement_on_surface_2/demo/earth/shaders/arc_fs.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

#version 330

uniform vec3 u_color;
uniform vec4 u_color;
uniform vec4 u_plane;


Expand All @@ -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;
}

0 comments on commit f8ccbb1

Please sign in to comment.