mirror of https://github.com/CGAL/cgal
added separate shader for drawing arcs
This commit is contained in:
parent
db222f07f4
commit
d3dc562857
|
|
@ -115,7 +115,7 @@ void MainWidget::init_geometry()
|
|||
void MainWidget::init_shader_programs()
|
||||
{
|
||||
init_sp_smooth();
|
||||
init_sp_color_only();
|
||||
init_sp_per_vertex_color();
|
||||
}
|
||||
void MainWidget::init_sp_smooth()
|
||||
{
|
||||
|
|
@ -124,11 +124,11 @@ void MainWidget::init_sp_smooth()
|
|||
m_sp_smooth.init(vs, "", fs);
|
||||
|
||||
}
|
||||
void MainWidget::init_sp_color_only()
|
||||
void MainWidget::init_sp_per_vertex_color()
|
||||
{
|
||||
const char* vs = "shaders/color_only_vs.glsl";
|
||||
const char* fs = "shaders/color_only_fs.glsl";
|
||||
m_sp_color_only.init(vs, "", fs);
|
||||
m_sp_per_vertex_color.init(vs, "", fs);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -170,12 +170,23 @@ void MainWidget::paintGL()
|
|||
|
||||
// WORLD COORDINATE AXES & GEODESIC ARCS
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
auto& sp = m_sp_color_only;
|
||||
auto& sp = m_sp_per_vertex_color;
|
||||
sp.use();
|
||||
sp.set_uniform("u_mvp", mvp);
|
||||
|
||||
|
||||
m_world_coord_axes->draw();
|
||||
|
||||
sp.unuse();
|
||||
}
|
||||
|
||||
// GEODESIC ARCS
|
||||
{
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
auto& sp = m_sp_per_vertex_color;
|
||||
sp.use();
|
||||
sp.set_uniform("u_mvp", mvp);
|
||||
|
||||
// compute the cutting plane
|
||||
auto c = m_camera.get_pos();
|
||||
const auto d = c.length();
|
||||
|
|
@ -184,16 +195,10 @@ void MainWidget::paintGL()
|
|||
const auto n = (c / d); // plane unit normal vector
|
||||
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));
|
||||
std::cout << plane << std::endl;
|
||||
QVector4D plane(n.x(), n.y(), n.z(), -QVector3D::dotProduct(p, n));
|
||||
sp.set_uniform("u_plane", plane);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
m_geodesic_arcs->draw();
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
sp.set_uniform("u_plane", QVector4D(0,0,0,0));// ad-hoc
|
||||
m_world_coord_axes->draw();
|
||||
|
||||
sp.unuse();
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,7 @@ protected:
|
|||
|
||||
void init_shader_programs();
|
||||
void init_sp_smooth();
|
||||
void init_sp_color_only();
|
||||
void init_sp_per_vertex_color();
|
||||
|
||||
private:
|
||||
// Objects in the scene
|
||||
|
|
@ -55,7 +55,8 @@ private:
|
|||
|
||||
// Shaders
|
||||
Shader_program m_sp_smooth;
|
||||
Shader_program m_sp_color_only;
|
||||
Shader_program m_sp_per_vertex_color;
|
||||
Shader_program m_sp_arc;
|
||||
|
||||
// Camera & controls
|
||||
Camera m_camera;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
|
||||
#version 330
|
||||
|
||||
uniform vec3 u_color;
|
||||
uniform vec4 u_plane;
|
||||
|
||||
in vec3 v_color;
|
||||
|
||||
in vec3 v_pos;
|
||||
out vec4 out_color;
|
||||
|
||||
|
|
@ -13,5 +14,5 @@ void main()
|
|||
if( dot(u_plane, vec4(v_pos, 1)) < 0 )
|
||||
discard;
|
||||
|
||||
out_color = vec4(v_color, 1);
|
||||
out_color = vec4(u_color, 1);
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
|
||||
#version 330
|
||||
|
||||
layout (location = 0) in vec3 a_pos;
|
||||
|
||||
uniform mat4 u_mvp;
|
||||
|
||||
out vec3 v_pos;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
v_pos = a_pos;
|
||||
gl_Position = u_mvp * vec4(a_pos.xyz, 1);
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#version 330
|
||||
|
||||
uniform vec4 u_plane;
|
||||
|
||||
in vec3 v_color;
|
||||
out vec4 out_color;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
out_color = vec4(v_color, 1);
|
||||
}
|
||||
|
|
@ -7,12 +7,10 @@ layout (location = 1) in vec3 a_color;
|
|||
uniform mat4 u_mvp;
|
||||
|
||||
out vec3 v_color;
|
||||
out vec3 v_pos;
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
v_color = a_color;
|
||||
v_pos = a_pos;
|
||||
gl_Position = u_mvp * vec4(a_pos.xyz, 1);
|
||||
}
|
||||
Loading…
Reference in New Issue