Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
directcolor.hpp
Go to the documentation of this file.
1 
23 #ifndef __DIRECTCOLOR__
24 #define __DIRECTCOLOR__
25 
26 #include <tucano/tucano.hpp>
27 #include <tucano/camera.hpp>
28 
29 namespace Tucano
30 {
31 namespace Effects
32 {
33 
38 {
39 
40 private:
41 
44 
46  Eigen::Vector4f default_color = Eigen::Vector4f(0.7, 0.7, 0.7, 1.0);
47 
48 public:
49 
53  DirectColor (void)
54  {}
55 
59  virtual void initialize (void)
60  {
61  // searches in default shader directory (/shaders) for shader files directcolor.(vert,frag,geom,comp)
62  loadShader(directcolor_shader, "directcolor") ;
63  }
64 
68  void setDefaultColor ( Eigen::Vector4f& color )
69  {
70  default_color = color;
71  }
72 
77  void render (Tucano::Mesh& mesh, const Tucano::Camera& camera)
78  {
79 
80  Eigen::Vector4f viewport = camera.getViewport();
81  glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
82 
83  directcolor_shader.bind();
84 
85  // sets all uniform variables for the phong shader
86  directcolor_shader.setUniform("projectionMatrix", camera.getProjectionMatrix());
87  directcolor_shader.setUniform("modelMatrix", mesh.getModelMatrix());
88  directcolor_shader.setUniform("viewMatrix", camera.getViewMatrix());
89  directcolor_shader.setUniform("has_color", mesh.hasAttribute("in_Color"));
90  directcolor_shader.setUniform("default_color", default_color);
91 
92  mesh.setAttributeLocation(directcolor_shader);
93 
94  glEnable(GL_DEPTH_TEST);
95  mesh.render();
96 
97  directcolor_shader.unbind();
98  }
99 
100 };
101 }
102 }
103 
104 
105 #endif
void getViewMatrix(GLdouble *matrix)
Return the modelview matrix as a GLdouble array.
Definition: camera.hpp:126
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 render(Tucano::Mesh &mesh, const Tucano::Camera &camera)
Render the mesh given a camera.
Definition: directcolor.hpp:77
Tucano::Shader directcolor_shader
Phong Shader.
Definition: directcolor.hpp:43
bool hasAttribute(const string &name) const
Returns wether an attribute exists or not.
Definition: mesh.hpp:503
virtual void initialize(void)
Load and initialize shaders.
Definition: directcolor.hpp:59
void unbind(void)
Disables the shader program.
Definition: shader.hpp:1184
DirectColor(void)
Default constructor.
Definition: directcolor.hpp:53
virtual Shader * loadShader(string shader_name)
Loads a shader by filename, initializes it, and inserts in shaders list.
Definition: effect.hpp:73
Eigen::Vector4f default_color
Default color.
Definition: directcolor.hpp:46
virtual void render(void)
Render the mesh triangles. The method binds the buffers, calls the method to render triangles...
Definition: mesh.hpp:756
Renders a mesh without illumination, using directly vertex color.
Definition: directcolor.hpp:37
Eigen::Affine3f getModelMatrix(void) const
Returns the model matrix.
Definition: model.hpp:103
void setDefaultColor(Eigen::Vector4f &color)
Sets the default color, usually used for meshes without color attribute.
Definition: directcolor.hpp:68
void bind(void)
Enables the shader program for usage.
Definition: shader.hpp:1176
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 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 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