Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
wireframe.hpp
Go to the documentation of this file.
1 
23 #ifndef __WIREFRAME__
24 #define __WIREFRAME__
25 
26 #include <tucano/effect.hpp>
27 #include <tucano/camera.hpp>
28 #include <tucano/mesh.hpp>
29 
30 namespace Tucano
31 {
32 namespace Effects
33 {
34 
38 class Wireframe : public Tucano::Effect
39 {
40 
41 private:
42 
45 
47  Eigen::Vector4f line_color = Eigen::Vector4f (0.0, 0.0, 0.0, 1.0);
48 
50  float thickness = 0.05;
51 
53  bool draw_faces = true;
54 
55 public:
56 
60  Wireframe (void)
61  {}
62 
66  virtual void initialize (void)
67  {
68  // searches in default shader directory (/shaders) for shader files wireframeShader.(vert,frag,geom,comp)
69  loadShader(wireframe_shader, "wireframe") ;
70  }
71 
75  void setLineColor ( const Eigen::Vector4f& color )
76  {
77  line_color = color;
78  }
79 
84  void setEdgeThickness (float value)
85  {
86  thickness = value;
87  }
88 
89 
96  void render (Tucano::Mesh& mesh, const Tucano::Camera& camera, const Tucano::Camera& lightTrackball)
97  {
98 
99  Eigen::Vector4f viewport = camera.getViewport();
100  glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
101 
102  wireframe_shader.bind();
103 
104  // sets all uniform variables for the wireframe shader
105  wireframe_shader.setUniform("projectionMatrix", camera.getProjectionMatrix());
106  wireframe_shader.setUniform("modelMatrix", mesh.getModelMatrix());
107  wireframe_shader.setUniform("viewMatrix", camera.getViewMatrix());
108  wireframe_shader.setUniform("lightViewMatrix", lightTrackball.getViewMatrix());
109  wireframe_shader.setUniform("has_color", mesh.hasAttribute("in_Color"));
110  wireframe_shader.setUniform("default_color", mesh.getColor());
111  wireframe_shader.setUniform("line_color", line_color);
112  wireframe_shader.setUniform("thickness", thickness);
113 
114  Tucano::Misc::errorCheckFunc(__FILE__, __LINE__);
115  mesh.setAttributeLocation(wireframe_shader);
116 
117  mesh.render();
118 
119  wireframe_shader.unbind();
120  }
121 
122 
123 };
124 }
125 }
126 
127 
128 #endif
Eigen::Vector4f getColor(void)
Returns the default color of the model.
Definition: model.hpp:56
void getViewMatrix(GLdouble *matrix)
Return the modelview matrix as a GLdouble array.
Definition: camera.hpp:126
virtual void initialize(void)
Load and initialize shaders.
Definition: wireframe.hpp:66
void getProjectionMatrix(GLdouble *matrix)
Return the projection matrix as a GLdouble array.
Definition: camera.hpp:142
Definition: bufferobject.hpp:34
A Shader object represents one GLSL program.
Definition: shader.hpp:45
void setEdgeThickness(float value)
Set shininess exponent.
Definition: wireframe.hpp:84
void errorCheckFunc(std::string file, int line, std::string message="")
GL error check method.
Definition: misc.hpp:53
void render(Tucano::Mesh &mesh, const Tucano::Camera &camera, const Tucano::Camera &lightTrackball)
Render the mesh given a camera and light, using a Wireframe shader.
Definition: wireframe.hpp:96
bool hasAttribute(const string &name) const
Returns wether an attribute exists or not.
Definition: mesh.hpp:503
Tucano::Shader wireframe_shader
Phong Shader.
Definition: wireframe.hpp:44
void unbind(void)
Disables the shader program.
Definition: shader.hpp:1184
virtual Shader * loadShader(string shader_name)
Loads a shader by filename, initializes it, and inserts in shaders list.
Definition: effect.hpp:73
virtual void render(void)
Render the mesh triangles. The method binds the buffers, calls the method to render triangles...
Definition: mesh.hpp:756
Wireframe(void)
Default constructor.
Definition: wireframe.hpp:60
Eigen::Affine3f getModelMatrix(void) const
Returns the model matrix.
Definition: model.hpp:103
void bind(void)
Enables the shader program for usage.
Definition: shader.hpp:1176
float thickness
Edge thickness.
Definition: wireframe.hpp:50
Renders a mesh with wireframe edges and flat faces in a single pass.
Definition: wireframe.hpp:38
A common Mesh, usually containing triagles or points.
Definition: mesh.hpp:194
Defines an abstract camera with a projection and view matrices.
Definition: camera.hpp:37
void setAttributeLocation(Shader *shader)
Automatically sets the attribute locations for a given Shader.
Definition: mesh.hpp:541
Eigen::Vector4f line_color
Default color.
Definition: wireframe.hpp:47
Eigen::Vector4f getViewport(void) const
Returns the viewport coordinates.
Definition: camera.hpp:246
The Effect class is a holder for Shaders. It is completely optional, but is contains a few methods fo...
Definition: effect.hpp:43
void setLineColor(const Eigen::Vector4f &color)
Sets the line color.
Definition: wireframe.hpp:75
bool draw_faces
Flag to draw faces.
Definition: wireframe.hpp:53
void setUniform(GLint location, GLint a, GLint b, GLint c, GLint d)
Sets an uniform integer 4D vector (ivec4) given a location and the vector values. ...
Definition: shader.hpp:1258