18Mesh make_grid(
const int n= 10 )
25 float w= float(n-1) / 2;
26 for(
int x= 0; x < n; x++)
32 for(
int z= 0; z < n; z++)
55Mesh make_ground(
const int n= 10 )
60 int a= grid.
vertex(-n/2, -1, n/2);
61 int b= grid.
vertex( n/2, -1, n/2);
62 int c= grid.
vertex( n/2, -1, -n/2);
63 int d= grid.
vertex(-n/2, -1, -n/2);
77 camera.vertex(
Point(0, 0, 0));
78 camera.vertex(
Point(1, 0, 0));
80 camera.color(
Green());
81 camera.vertex(
Point(0, 0, 0));
82 camera.vertex(
Point(0, 1, 0));
85 camera.vertex(
Point(0, 0, 0));
86 camera.vertex(
Point(0, 0, 1));
98 camera.vertex(-1, -1, -1);
99 camera.vertex(-1, 1, -1);
100 camera.vertex(-1, 1, -1);
101 camera.vertex(1, 1, -1);
102 camera.vertex(1, 1, -1);
103 camera.vertex(1, -1, -1);
104 camera.vertex(1, -1, -1);
105 camera.vertex(-1, -1, -1);
108 camera.vertex(-1, -1, 1);
109 camera.vertex(-1, 1, 1);
110 camera.vertex(-1, 1, 1);
111 camera.vertex(1, 1, 1);
112 camera.vertex(1, 1, 1);
113 camera.vertex(1, -1, 1);
114 camera.vertex(1, -1, 1);
115 camera.vertex(-1, -1, 1);
118 camera.vertex(-1, -1, -1);
119 camera.vertex(-1, -1, 1);
120 camera.vertex(-1, 1, -1);
121 camera.vertex(-1, 1, 1);
122 camera.vertex(1, 1, -1);
123 camera.vertex(1, 1, 1);
124 camera.vertex(1, -1, -1);
125 camera.vertex(1, -1, 1);
140 m_repere= make_grid(20);
141 m_local= make_grid(2);
145 m_frustum= make_frustum();
146 m_frustum_cube=
read_mesh(
"data/frustum.obj");
157 m_mesh_program=
read_program(
"gkit2_tutos/deferred_mesh.glsl");
159 m_decal_program=
read_program(
"gkit2_tutos/deferred_decal.glsl");
168 m_ground.bounds(pmin, pmax);
173 m_framebuffer.clear_color(
Black());
174 m_framebuffer.clear_depth(1);
177 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
180 glDepthFunc(GL_LEQUAL);
181 glEnable(GL_DEPTH_TEST);
195 m_framebuffer.release();
198 glDeleteTextures(1, &m_texture);
205 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
229 m_framebuffer.bind(0,
true,
true,
false,
false,
false,
false);
231 draw(m_ground,
Identity(), view, projection);
250 Transform decal_projection=
Ortho(-2, 2, -2, 2,
float(0.1),
float(10));
258 draw(m_frustum, decal_model, view, projection);
263 draw(m_proxy, m_position * m, view, projection);
268 glUseProgram(m_decal_program);
276 program_uniform(m_decal_program,
"mvpMatrix", mvp);
285 Transform inv= decal_viewport * decal_projection * decal_view * m;
287 program_uniform(m_decal_program,
"invMatrix", inv);
291 m_framebuffer.use_color_texture(m_decal_program,
"color_texture", 1);
292 m_framebuffer.use_depth_texture(m_decal_program,
"depth_texture", 2);
295 glDepthMask(GL_FALSE);
296 m_frustum_cube.draw(m_decal_program);
298 glDepthMask(GL_TRUE);
303 draw(m_objet, m_position, view, projection);
306 draw(m_local, m_position, view, projection);
331 GLuint m_mesh_program;
332 GLuint m_decal_program;
336int main(
int argc,
char **argv )
const Orbiter & camera() const
renvoie l'orbiter gere par l'application.
AppCamera(const int width, const int height, const int major=3, const int minor=3)
constructeur, dimensions de la fenetre et version d'openGL.
int run()
execution de l'application.
representation d'un objet / maillage.
unsigned int vertex(const vec3 &p)
insere un sommet de position p, et ses attributs (s'ils sont definis par color(), texcoord(),...
Mesh & triangle(const unsigned int a, const unsigned int b, const unsigned int c)
Mesh & normal(const vec3 &n)
definit la normale du prochain sommet.
Mesh & color(const vec4 &c)
definit la couleur du prochain sommet.
void lookat(const Point ¢er, const float size)
observe le point center a une distance size.
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...
Transform view() const
renvoie la transformation vue.
int render()
a deriver pour afficher les objets. renvoie 1 pour continuer, 0 pour fermer l'application.
int quit()
a deriver pour detruire les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
int init()
a deriver pour creer les objets openGL. renvoie -1 pour indiquer une erreur, 0 sinon.
int window_height()
renvoie la hauteur de la fenetre de l'application.
void clear_key_state(const SDL_Keycode key)
desactive une touche du clavier.
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
int window_width()
renvoie la largeur de la fenetre de l'application.
Color Red()
utilitaire. renvoie une couleur rouge.
Color Yellow()
utilitaire. renvoie une couleur jaune.
Color Blue()
utilitaire. renvoie une couleur bleue.
Color Black()
utilitaire. renvoie une couleur noire.
Color Green()
utilitaire. renvoie une couleur verte.
Color White()
utilitaire. renvoie une couleur blanche.
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
Transform Viewport(const float width, const float height)
renvoie la matrice representant une transformation viewport.
Transform Identity()
construit la transformation identite.
Transform RotationX(const float a)
renvoie la matrice representation une rotation de angle degree autour de l'axe X.
Transform RotationY(const float a)
renvoie la matrice representation une rotation de a degree autour de l'axe Y.
Transform Ortho(const float left, const float right, const float bottom, const float top, const float znear, const float zfar)
renvoie la matrice representant une transformation orthographique, passage d'un cube []x[]x[] vers [-...
Transform Translation(const Vector &v)
renvoie la matrice representant une translation par un vecteur.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
int screenshot(const char *filename)
enregistre le contenu de la fenetre dans un fichier. doit etre de type .png / .bmp
GLuint read_program(const char *filename, const char *definitions)
int program_print_errors(const GLuint program, const char *filename)
affiche les erreurs de compilation.
int release_program(const GLuint program)
detruit les shaders et le program.
void program_use_texture(const GLuint program, const char *uniform, const int unit, const GLuint texture, const GLuint sampler)
configure le pipeline et le shader program pour utiliser une texture, et des parametres de filtrage,...
GLuint read_texture(const int unit, const char *filename, const GLenum texel_type)
representation d'un point 3d.