a deriver pour afficher les objets. renvoie 1 pour continuer, 0 pour fermer l'application.
231 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
236 reload_program(m_program,
"tutos/M2/is.glsl");
244 m_mesh.
bounds(pmin, pmax);
245 m_camera.
lookat(pmin, pmax);
250 unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
251 if(mb & SDL_BUTTON(1))
253 else if(mb & SDL_BUTTON(3))
255 else if(mb & SDL_BUTTON(2))
270 SDL_GetMouseState(&mx, &my);
273 printf(
"pixel %f %f\n", pixel.x, pixel.y);
278 m_camera.
frame(0, d0, dx0, dy0);
282 m_camera.
frame(1, d1, dx1, dy1);
285 Point o= d0 + pixel.x*dx0 + pixel.y*dy0;
286 Point e= d1 + pixel.x*dx1 + pixel.y*dy1;
293 if(intersect(ray, hit))
299 #pragma omp parallel for schedule(dynamic, 16)
300 for(
int y= 0; y < m_hitp.
height(); y++)
301 for(
int x= 0; x < m_hitp.
width(); x++)
304 m_hitp(x, y)=
Black();
305 m_hitn(x, y)=
Black();
306 m_hitv(x, y)=
Black();
308 Point o= d0 + x*dx0 + y*dy0;
309 Point e= d1 + x*dx1 + y*dy1;
313 if(intersect(ray, hit))
315 m_hitp(x, y)=
Color(hit.p.x, hit.p.y, hit.p.z);
316 m_hitn(x, y)=
Color(hit.n.x, hit.n.y, hit.n.z);
318 Ray shadow(hit.p + hit.n * 0.001f, point + normal * 0.001f);
321 if(intersect(shadow, shadow_hit))
324 m_hitv(x, y)=
Color(v, v, v);
329 glActiveTexture(GL_TEXTURE0);
330 glBindTexture(GL_TEXTURE_2D, m_ptexture);
331 glTexSubImage2D(GL_TEXTURE_2D, 0,
333 GL_RGBA, GL_FLOAT, m_hitp.
data());
335 glActiveTexture(GL_TEXTURE0 +1);
336 glBindTexture(GL_TEXTURE_2D, m_ntexture);
337 glTexSubImage2D(GL_TEXTURE_2D, 0,
339 GL_RGBA, GL_FLOAT, m_hitn.
data());
341 glActiveTexture(GL_TEXTURE0 +2);
342 glBindTexture(GL_TEXTURE_2D, m_vtexture);
343 glTexSubImage2D(GL_TEXTURE_2D, 0,
345 GL_RGBA, GL_FLOAT, m_hitv.
data());
352 glBindVertexArray(m_vao);
353 glUseProgram(m_program);
361 glActiveTexture(GL_TEXTURE0);
362 glBindTexture(GL_TEXTURE_2D, m_ptexture);
363 glActiveTexture(GL_TEXTURE0 +1);
364 glBindTexture(GL_TEXTURE_2D, m_ntexture);
365 glActiveTexture(GL_TEXTURE0 +2);
366 glBindTexture(GL_TEXTURE_2D, m_vtexture);
368 glDrawArrays(GL_TRIANGLES, 0, 3);
372 draw(m_mesh, m_camera);
381 sprintf(tmp,
"screenshot%02d.png", n++);
382 printf(
"writing %s...\n", tmp);
int height() const
renvoie la hauteur de l'image.
const void * data() const
renvoie un pointeur sur le stockage des couleurs des pixels.
int width() const
renvoie la largeur de l'image.
void bounds(Point &pmin, Point &pmax) const
renvoie min et max les coordonnees des extremites des positions des sommets de l'objet (boite engloba...
void lookat(const Point ¢er, const float size)
observe le point center a une distance size.
void frame(const float z, Point &dO, Vector &dx, Vector &dy) const
void move(const float z)
rapproche / eloigne la camera du centre.
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...
void translation(const float x, const float y)
deplace le centre / le point observe.
void rotation(const float x, const float y)
change le point de vue / la direction d'observation.
void clear_key_state(const SDL_Keycode key)
desactive une touche du clavier.
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
Color Black()
utilitaire. renvoie une couleur noire.
int screenshot(const char *filename)
enregistre le contenu de la fenetre dans un fichier. doit etre de type .png / .bmp
void program_uniform(const GLuint program, const char *uniform, const std::vector< unsigned > &v)
affecte un tableau de valeurs a un uniform du shader program.
representation d'une couleur (rgba) transparente ou opaque.
intersection avec un triangle.
representation d'un point 3d.
representation d'un vecteur 3d.
vecteur generique, utilitaire.