21 GLuint program_cubemap;
 
   22 GLuint program_render_cubemap;
 
   24 GLuint texture_cubemap;
 
   48     program_render_cubemap= 
read_program(
"tutos/render_cubemap.glsl");
 
   64     glGenVertexArrays(1, &vao);
 
   65     glBindVertexArray(vao);
 
   68     glGenBuffers(1, &vertex_buffer);
 
   69     glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer);
 
   73     glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
 
   74     glEnableVertexAttribArray(0);
 
   77     if(!mesh.has_normal())
 
   79         printf(
"[oops]  pas de normales...\n");
 
   83     glGenBuffers(1, &normal_buffer);
 
   84     glBindBuffer(GL_ARRAY_BUFFER, normal_buffer);
 
   87     glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
 
   88     glEnableVertexAttribArray(1);
 
   93     glBindBuffer(GL_ARRAY_BUFFER, 0);
 
  101         glGenTextures(1, &texture_cubemap);
 
  102         glBindTexture(GL_TEXTURE_CUBE_MAP, texture_cubemap);
 
  103         for(
int i= 0; i < 6; i++)
 
  105             glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X +i, 0,
 
  107                 GL_RGBA, GL_UNSIGNED_BYTE, 
nullptr);
 
  109         glGenerateMipmap(GL_TEXTURE_CUBE_MAP);    
 
  112         glGenTextures(1, &depth_cubemap);
 
  113         glBindTexture(GL_TEXTURE_CUBE_MAP, depth_cubemap);
 
  114         for(
int i= 0; i < 6; i++)
 
  116             glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X +i, 0,
 
  117                 GL_DEPTH_COMPONENT, w, h, 0,
 
  118                 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 
nullptr);
 
  121         glBindTexture(GL_TEXTURE_CUBE_MAP, 0);        
 
  125     glGenFramebuffers(1, &framebuffer);
 
  126     glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
 
  127     glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, texture_cubemap, 0);
 
  128     glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depth_cubemap, 0);
 
  130     glBindFramebuffer(GL_FRAMEBUFFER, 0);
 
  134     glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
 
  135     glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
 
  138     glGenVertexArrays(1, &vao_null);
 
  139     glBindVertexArray(vao_null);
 
  143     glBindVertexArray(0);
 
  146     glClearColor(0.2f, 0.2f, 0.2f, 1);
 
  149     glDepthFunc(GL_LEQUAL);     
 
  152     glEnable(GL_DEPTH_TEST);
 
  157     glDisable(GL_CULL_FACE);
 
  166     glDeleteVertexArrays(1, &vao);
 
  167     glDeleteVertexArrays(1, &vao_null);
 
  168     glDeleteBuffers(1, &vertex_buffer);
 
  169     glDeleteBuffers(1, &normal_buffer);
 
  170     glDeleteTextures(1, &texture_cubemap);
 
  171     glDeleteTextures(1, &depth_cubemap);
 
  172     glDeleteFramebuffers(1, &framebuffer);
 
  179     glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
 
  180     glViewport(0, 0, 1024, 1024);
 
  184     float black[4]= { 0, 0, 0, 0 };
 
  185     glClearBufferfv(GL_COLOR, 0, black);
 
  188     glClearBufferfv(GL_DEPTH, 0, &one);
 
  207         glBindVertexArray(vao);
 
  208         glUseProgram(program_render_cubemap);
 
  209         glUniformMatrix4fv(glGetUniformLocation(program_render_cubemap, 
"projectionMatrix"), 1, GL_TRUE, projection.buffer());
 
  210         glUniformMatrix4fv(glGetUniformLocation(program_render_cubemap, 
"modelMatrix"), 1, GL_TRUE, model.buffer());
 
  211         glUniformMatrix4fv(glGetUniformLocation(program_render_cubemap, 
"viewMatrix"), 6, GL_TRUE, faces[0].buffer());
 
  214         glDrawArraysInstanced(GL_TRIANGLES, 0, vertex_count, 6);
 
  218     glBindFramebuffer(GL_FRAMEBUFFER, 0);
 
  219     glBindTexture(GL_TEXTURE_CUBE_MAP, texture_cubemap);
 
  220     glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
 
  223     glBindFramebuffer(GL_FRAMEBUFFER, 0);
 
  226     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
  230     unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
 
  233     if(mb & SDL_BUTTON(1))              
 
  237     else if(mb & SDL_BUTTON(3))         
 
  241     else if(mb & SDL_BUTTON(2))         
 
  257     Transform mvp= projection * view * model;
 
  261         glBindVertexArray(vao);
 
  262         glUseProgram(program);
 
  269         glBindTexture(GL_TEXTURE_CUBE_MAP, texture_cubemap);
 
  272         GLint location= glGetUniformLocation(program, 
"texture0");
 
  273         glUniform1i(location, 0);
 
  276         glDrawArrays(GL_TRIANGLES, 0, vertex_count);
 
  281         glBindVertexArray(vao_null);
 
  282         glUseProgram(program_cubemap);
 
  285         glBindTexture(GL_TEXTURE_CUBE_MAP, texture_cubemap);
 
  288         GLint location= glGetUniformLocation(program_cubemap, 
"texture0");
 
  289         glUniform1i(location, 0);
 
  296         glDrawArrays(GL_TRIANGLES, 0, 3);
 
  300     glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
 
  302     glBindVertexArray(0);
 
  308 int main( 
int argc, 
char **argv )
 
  321     if(GLEW_ARB_shader_viewport_layer_array)
 
  322         printf(
"ARB_shader_viewport_layer_array supported\n");
 
  326         printf(
"[error] ARB_shader_viewport_layer_array NOT supported...\n");
 
  333         printf(
"[error] init failed.\n");
 
representation d'un objet / maillage.
 
const float * vertex_buffer() const
renvoie l'adresse de la position du premier sommet. permet de construire les vertex buffers openGL....
 
void bounds(Point &pmin, Point &pmax) const
renvoie min et max les coordonnees des extremites des positions des sommets de l'objet (boite engloba...
 
std::size_t vertex_buffer_size() const
renvoie la longueur (en octets) du vertex buffer.
 
int vertex_count() const
renvoie le nombre de sommets.
 
void release()
detruit les objets openGL.
 
std::size_t normal_buffer_size() const
renvoie la longueur (en octets) du normal buffer.
 
const float * normal_buffer() const
renvoie l'adresse de la normale du premier sommet. par convention, la normale est un vec3,...
 
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
 
void lookat(const Point ¢er, const float size)
observe le point center a une distance size.
 
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.
 
Transform view() const
renvoie la transformation vue.
 
Context create_context(Window window)
cree et configure un contexte opengl
 
int window_height()
renvoie la hauteur de la fenetre de l'application.
 
void release_window(Window window)
destruction de la fenetre.
 
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().
 
Window create_window(const int w, const int h, const int major, const int minor, const int samples)
creation d'une fenetre pour l'application.
 
void release_context(Context context)
detruit le contexte openGL.
 
int window_width()
renvoie la largeur de la fenetre de l'application.
 
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
 
Transform Identity()
construit la transformation identite.
 
Transform Perspective(const float fov, const float aspect, const float znear, const float zfar)
renvoie la matrice representant une transformation projection perspective.
 
Transform Lookat(const Point &from, const Point &to, const Vector &up)
renvoie la matrice representant le placement et l'orientation d'une camera pour observer le point to.
 
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
 
GLuint read_program(const char *filename, const char *definitions)
 
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.
 
int program_print_errors(const GLuint program)
affiche les erreurs de compilation.
 
int release_program(const GLuint program)
detruit les shaders et le program.
 
int init(std::vector< const char * > &options)
 
representation d'un point 3d.
 
representation d'un vecteur 3d.
 
int run(Window window, int(*draw)())
boucle de gestion des evenements de l'application.