Tucano  0.1
A library for rapid prototyping with modern OpenGL and GLSL
gradientfilter.hpp
Go to the documentation of this file.
1 
23 #ifndef __GRADIENT__
24 #define __GRADIENT__
25 
26 #include <tucano/tucano.hpp>
27 
28 namespace Tucano
29 {
30 namespace Effects
31 {
32 
33 
39 {
40 
41 private:
42 
45 
48 
50  bool horizontal = true;
51 
53  bool vertical = true;
54 
55 public:
56 
60  GradientFilter (void) {}
61 
65  virtual void initialize()
66  {
67  loadShader(shader, "gradientfilter");
68  quad.createQuad();
69  }
70 
74  void renderTexture(Tucano::Texture& tex, Eigen::Vector2i viewport)
75  {
76  glViewport(0, 0, viewport[0], viewport[1]);
77 
78  shader.bind();
79  shader.setUniform("imageTexture", tex.bind());
80  shader.setUniform("hdir", horizontal);
81  shader.setUniform("vdir", vertical);
82  quad.render();
83 
84  shader.unbind();
85  tex.unbind();
86  }
87 
93  void setDirections (bool hgrad, bool vgrad)
94  {
95  horizontal = hgrad;
96  vertical = vgrad;
97  }
98 
99 };
100 }
101 
102 }
103 #endif
void createQuad(void)
Sets the mesh as Unit Quad.
Definition: mesh.hpp:841
Tucano::Shader shader
The mean filter shader.
Definition: gradientfilter.hpp:44
Definition: bufferobject.hpp:34
bool vertical
Apply gradient in vertical direction.
Definition: gradientfilter.hpp:53
void bind(int texture_unit)
Binds the texture to a given unit. Note that if there is another texture already binded to this unit...
Definition: texture.hpp:285
A Shader object represents one GLSL program.
Definition: shader.hpp:45
A simple Sobel filter for image processing.
Definition: gradientfilter.hpp:38
bool horizontal
Apply gradient in horizontal direction.
Definition: gradientfilter.hpp:50
void setDirections(bool hgrad, bool vgrad)
Sets flags for computing gradient in horizontal and vertical directions.
Definition: gradientfilter.hpp:93
virtual void initialize()
Initializes the effect, creating and loading the shader.
Definition: gradientfilter.hpp:65
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
GradientFilter(void)
Default Constructor.
Definition: gradientfilter.hpp:60
Tucano::Mesh quad
A quad to be rendered forcing one call of the fragment shader per image pixel.
Definition: gradientfilter.hpp:47
An OpenGL texture. It can be a simple texture or an FBO texture.
Definition: texture.hpp:41
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
The Effect class is a holder for Shaders. It is completely optional, but is contains a few methods fo...
Definition: effect.hpp:43
void unbind(void)
Unbinds this texture and frees the texture unit.
Definition: texture.hpp:367
void renderTexture(Tucano::Texture &tex, Eigen::Vector2i viewport)
Applies the gradient filter to an image.
Definition: gradientfilter.hpp:74
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