gKit2 light
Loading...
Searching...
No Matches
draw.h
Go to the documentation of this file.
1
2#ifndef _DRAW_H
3#define _DRAW_H
4
5#include "mesh.h"
6#include "orbiter.h"
7#include "window.h"
8#include "program.h"
9
10
12
14
16void draw( Mesh& m, const Transform& model, const Transform& view, const Transform& projection );
18void draw( Mesh& m, const Transform& model, const Transform& view, const Transform& projection, const GLuint texture );
19
21void draw( Mesh& m, Orbiter& camera );
23void draw( Mesh& m, const Transform& model, Orbiter& camera );
24
26void draw( Mesh& m, Orbiter& camera, const GLuint texture );
28void draw( Mesh& m, const Transform& model, Orbiter& camera, const GLuint texture );
29
31
32
33void draw( const TriangleGroup& group, Mesh& mesh, Orbiter& camera );
35void draw( const TriangleGroup& group, Mesh& mesh, const Transform& model, Orbiter& camera );
37void draw( const TriangleGroup& group, Mesh& mesh, const Transform& model, const Transform& view, const Transform& projection );
38
40void draw( const TriangleGroup& group, Mesh& mesh, Orbiter& camera, const GLuint texture );
42void draw( const TriangleGroup& group, Mesh& mesh, const Transform& model, Orbiter& camera, const GLuint texture );
44void draw( const TriangleGroup& group, Mesh& mesh, const Transform& model, const Transform& view, const Transform& projection, const GLuint texture );
46
67{
68public:
70 DrawParam( ) : flags( USE_SUN ),
71 m_model(), m_view(), m_projection(),
72 m_light( Point(1, 1, 1) ), m_light_color( White() ),
73 m_sun( normalize( Vector(0.5, 0.25, 0.5) ) ), m_sun_color( Color(1) ),
74 m_sky( normalize( Vector(0, 1, 0) ) ), m_sky_color( Color(0.2) ),
75 m_texture(0),
76 m_alpha_min(0.3),
77 m_normals_scale(0.2),
78 m_material( Color(0.7) )
79 {}
80
82 DrawParam& model( const Transform& m ) { m_model= m; return *this; }
84 DrawParam& view( const Transform& m ) { m_view= m; return *this; }
86 DrawParam& projection( const Transform& m ) { m_projection= m; return *this; }
87
89 DrawParam& camera( Orbiter& o ) { m_view= o.view(); m_projection= o.projection(); return *this; }
91 DrawParam& camera( Orbiter& o, const int width, const int height, const float fov ) { m_view= o.view(); m_projection= o.projection(width, height, fov); return *this; }
93 DrawParam& light( const Point& p, const Color& c= White() ) { update(flags, USE_LIGHT); m_light= p; m_light_color=c; return *this; }
95 DrawParam& light( const bool flag= true ) { update(flags, USE_LIGHT, flag); return *this; }
97 DrawParam& sun( const Vector& d, const Color& c ) { update(flags, USE_SUN); m_sun= d; m_sun_color=c; return *this; }
99 DrawParam& sun( const bool flag= true ) { update(flags, USE_SUN, flag); return *this; }
100
102 DrawParam& sky( const Vector& d, const Color& c ) { update(flags, USE_SKY); m_sky= d; m_sky_color=c; return *this; }
104 DrawParam& sky( const bool flag= true ) { update(flags, USE_SKY, flag); return *this; }
105
107 DrawParam& texture( const GLuint t ) { update(flags, USE_TEXTURE, (t > 0)); m_texture= t; return *this; }
108
110 DrawParam& alpha_texture( const GLuint t, const float a= 0.5 ) { update(flags, USE_ALPHATEST, (a > 0)); m_alpha_min= a; m_texture= t; return *this; }
111
113 DrawParam& shading( const bool flag= true ) { update(flags, USE_SHADING, flag); return *this; }
114
116 DrawParam& material( const Material& material ) { update(flags, USE_SHADING | USE_MATERIAL); m_material= material; return *this; }
118 DrawParam& material( const bool flag= true ) { update(flags, USE_MATERIAL, flag); return *this; }
119
121 DrawParam& debug_normals( const float s= 0.2 ) { update(flags, DEBUG_NORMALS, (s > 0)); m_normals_scale= s; return *this;}
123 DrawParam& wireframe( const bool flag= true ) { update(flags, DEBUG_NORMALS, flag); m_normals_scale= 0; return *this;}
125 DrawParam& debug_texcoords( const bool flag= true ) { update(flags, DEBUG_TEXCOORDS, flag); return *this;}
126
128 void draw( Mesh& mesh );
129 void draw( Mesh& mesh, const Transform& model );
130 void draw( const TriangleGroup& group, Mesh& mesh );
131
132protected:
133 void draw( const unsigned first, const unsigned count, Mesh& mesh );
134
136 enum : unsigned
137 {
138 USE_TEXCOORD = 1,
139 USE_NORMAL= 2,
140 USE_COLOR= 4,
141 USE_TEXTURE= 8,
142 USE_ALPHATEST= 16,
143 USE_SHADING= 32,
144 USE_LIGHT= 64,
145 USE_SUN= 128,
146 USE_SKY= 256,
147 USE_ENVMAP= 512,
148 USE_MATERIAL= 1024,
149
150 DEBUG_NORMALS= 1u << 20,
151 DEBUG_TEXCOORDS= 1u << 21
152 };
153
154 unsigned flags;
155
156 unsigned create_flags( const bool use_texcoord, const bool use_normal, const bool use_color );
157 unsigned update( unsigned &flags, const unsigned option, const bool use= true );
158 bool flag( const unsigned option );
159
161 GLuint create_program( const GLenum primitives, const unsigned flags );
163 GLuint create_debug_normals_program( const GLenum primitives, const unsigned flags );
165 GLuint create_debug_texcoords_program( const GLenum primitives, const unsigned flags );
166
167 Transform m_model;
168 Transform m_view;
169 Transform m_projection;
170
171 Point m_light;
172 Color m_light_color;
173
174 Vector m_sun;
175 Color m_sun_color;
176 Vector m_sky;
177 Color m_sky_color;
178
179 GLuint m_texture;
180 GLuint m_envmap;
181 float m_alpha_min;
182 float m_normals_scale;
183
184 Material m_material;
185};
186
187
188void draw( Mesh& m, DrawParam& param );
189
190#endif
DrawParam & sun(const bool flag=true)
active / desactive le soleil.
Definition draw.h:99
DrawParam & sky(const Vector &d, const Color &c)
eclaire l'objet avec une source hemispherique de couleur c. le zenith se trouve dans la direction d.
Definition draw.h:102
DrawParam & alpha_texture(const GLuint t, const float a=0.5)
utilise une texture semi transparente, si l'alpha du texel est plus petit que a, le pixel est transpa...
Definition draw.h:110
DrawParam()
constructeur par defaut.
Definition draw.h:70
GLuint create_program(const GLenum primitives, const unsigned flags)
construit un shader program configure pour l'ensemble d'options.
Definition draw.cpp:115
DrawParam & camera(Orbiter &o)
utilise les transformations view et projection definies par une camera.
Definition draw.h:89
GLuint create_debug_texcoords_program(const GLenum primitives, const unsigned flags)
construit un shader program / debug des coordonnees de texture.
Definition draw.cpp:165
DrawParam & light(const bool flag=true)
active / desactive la source ponctuelle.
Definition draw.h:95
DrawParam & wireframe(const bool flag=true)
visualise les aretes des triangles.
Definition draw.h:123
void draw(Mesh &mesh)
dessine l'objet avec l'ensemble des parametres definis.
Definition draw.cpp:196
GLuint create_debug_normals_program(const GLenum primitives, const unsigned flags)
construit un shader program / debug des normales.
Definition draw.cpp:153
DrawParam & model(const Transform &m)
modifie la transformation model utilisee pour afficher l'objet.
Definition draw.h:82
DrawParam & debug_normals(const float s=0.2)
visualise les normales des sommets des triangles et les normales geometrique des triangles
Definition draw.h:121
DrawParam & material(const bool flag=true)
active / desactive la matiere pour dessiner un objet.
Definition draw.h:118
DrawParam & view(const Transform &m)
modifie la transformation view utilisee pour afficher l'objet.
Definition draw.h:84
DrawParam & debug_texcoords(const bool flag=true)
visualise les coordonnees de textures des sommets des triangles.
Definition draw.h:125
DrawParam & camera(Orbiter &o, const int width, const int height, const float fov)
utilise les transformations view et projection definies par une camera. parametres explicites de la p...
Definition draw.h:91
DrawParam & sky(const bool flag=true)
active / desactive le ciel
Definition draw.h:104
DrawParam & light(const Point &p, const Color &c=White())
eclaire l'objet avec une source ponctuelle, de position p et de couleur c.
Definition draw.h:93
DrawParam & sun(const Vector &d, const Color &c)
eclaire l'objet avec une source directionnelle, de direction d et de couleur c.
Definition draw.h:97
DrawParam & projection(const Transform &m)
modifie la transformation projection utilisee pour afficher l'objet.
Definition draw.h:86
DrawParam & texture(const GLuint t)
plaque une texture opaque a la surface de l'objet.
Definition draw.h:107
DrawParam & material(const Material &material)
utilise une matiere pour dessiner un objet.
Definition draw.h:116
DrawParam & shading(const bool flag=true)
utilise une source de lumire pour eclairer l'objet, ou pas si flag= false.
Definition draw.h:113
representation d'un objet / maillage.
Definition mesh.h:121
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
Definition orbiter.h:17
Transform projection(const int width, const int height, const float fov)
fixe la projection reglee pour une image d'aspect width / height, et une demi ouverture de fov degres...
Definition orbiter.cpp:48
Transform view() const
renvoie la transformation vue.
Definition orbiter.cpp:41
void draw(Mesh &m, const Transform &model, const Transform &view, const Transform &projection)
dessine l'objet avec les transformations model, vue et projection.
Definition draw.cpp:36
Color White()
utilitaire. renvoie une couleur blanche.
Definition color.cpp:23
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition vec.cpp:167
@ USE_COLOR
inclut l'attribut couleur dans les buffers.
Definition mesh.h:115
@ USE_TEXCOORD
inclut l'attribut coordonnees de texture dans les buffers.
Definition mesh.h:113
@ USE_NORMAL
inclut l'attribut normale dans les buffers.
Definition mesh.h:114
representation d'un ensemble de triangles de meme matiere.
Definition mesh.h:103
representation d'une couleur (rgba) transparente ou opaque.
Definition color.h:14
representation d'un point 3d.
Definition vec.h:21
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition mat.h:21
representation d'un vecteur 3d.
Definition vec.h:67