16 Mesh make_grid(
const int n= 10 )
22 for(
int x= 0; x < n; x++)
24 float px= float(x) - float(n)/2 + .5f;
29 for(
int z= 0; z < n; z++)
31 float pz= float(z) - float(n)/2 + .5f;
65 repere= make_grid(10);
70 mesh=
read_mesh(
"/home/jciehl/scenes/bistro/exterior.obj");
80 program_record=
read_program(
"tutos/M2/fragment_record.glsl");
89 glGenBuffers(1, &buffer);
90 glBindBuffer(GL_ARRAY_BUFFER, buffer);
91 glBufferData(GL_ARRAY_BUFFER, size * 6*
sizeof(
float),
nullptr, GL_DYNAMIC_DRAW);
97 glGenVertexArrays(1, &vao_replay);
99 glBindVertexArray(vao_replay);
100 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*
sizeof(
float), (
const void *) (4*
sizeof(
unsigned)));
101 glEnableVertexAttribArray(0);
102 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*
sizeof(
float), (
const void *) (4*
sizeof(
unsigned) + 3*
sizeof(
float)));
103 glEnableVertexAttribArray(1);
106 glBindVertexArray(0);
107 glBindBuffer(GL_ARRAY_BUFFER, 0);
109 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
112 glDepthFunc(GL_LEQUAL);
113 glEnable(GL_DEPTH_TEST);
117 glEnable(GL_CULL_FACE);
133 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
144 static unsigned init= 0;
145 static unsigned zinit= 0;
150 zinit= (zinit +1) %2;
157 printf(
"Zpre pass OFF\n");
164 draw(mesh, model, view, projection);
167 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffer);
170 glClearBufferData(GL_SHADER_STORAGE_BUFFER, GL_R32F, GL_RED, GL_FLOAT, &zero);
179 unsigned indirect[]= { 0, 1, 0, 0};
180 glBufferSubData(GL_SHADER_STORAGE_BUFFER, 0,
sizeof(indirect), indirect);
182 glBindImageTexture(0, texture, 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32UI);
185 glClearTexImage(texture, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, &zero);
189 glBindVertexArray(vao);
190 glUseProgram(program_record);
196 glDrawArrays(GL_TRIANGLES, 0, n);
198 glMemoryBarrier( GL_ALL_BARRIER_BITS);
210 static unsigned replay= 0;
212 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
214 draw(repere,
Identity(), view, projection);
216 glBindVertexArray(vao_replay);
218 glBindBuffer(GL_PARAMETER_BUFFER_ARB, buffer);
219 glBindBuffer(GL_DRAW_INDIRECT_BUFFER, buffer);
221 glUseProgram(program_replay);
228 glDrawArrays(GL_POINTS, 0, replay);
231 static unsigned points= 1;
246 static bool video=
false;
252 if(video)
printf(
"start video capture...\n");
253 else printf(
"stop video capture.\n");
275 GLuint program_record;
276 GLuint program_replay;
280 int main(
int argc,
char **argv )
const Orbiter & camera() const
renvoie l'orbiter gere par l'application.
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(),...
GLuint create_buffers(const bool use_texcoord, const bool use_normal, const bool use_color, const bool use_material_index)
construit les buffers et le vertex array object necessaires pour dessiner l'objet avec 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...
int vertex_count() const
renvoie le nombre de sommets.
void release()
detruit les objets openGL.
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.
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.
int window_width()
renvoie la largeur de la fenetre de l'application.
Color Red()
utilitaire. renvoie une couleur rouge.
Color Blue()
utilitaire. renvoie une couleur bleue.
Color Green()
utilitaire. renvoie une couleur verte.
Color White()
utilitaire. renvoie une couleur blanche.
Transform Identity()
construit la transformation identite.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
int capture(const char *prefix)
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.
GLuint make_uint_texture(const int unit, const int width, const int height, const GLenum texel_type)
creation de textures pour stocker des donnees (autres qu'une couleur).
representation d'un point 3d.