16Mesh 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);
73 mesh.bounds(pmin, pmax);
76 vao= mesh.create_buffers(
false,
false,
false,
false );
77 n= mesh.vertex_count();
79 program_record=
read_program(
"gkit2_tutos/M2/fragment_record.glsl");
82 program_replay=
read_program(
"gkit2_tutos/M2/fragment.glsl");
88 glGenBuffers(1, &buffer);
89 glBindBuffer(GL_ARRAY_BUFFER, buffer);
90 glBufferData(GL_ARRAY_BUFFER, size * 6*
sizeof(
float),
nullptr, GL_DYNAMIC_DRAW);
96 glGenVertexArrays(1, &vao_replay);
98 glBindVertexArray(vao_replay);
99 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*
sizeof(
float), (
const void *) (1*
sizeof(
unsigned)));
100 glEnableVertexAttribArray(0);
101 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*
sizeof(
float), (
const void *) (1*
sizeof(
unsigned) + 3*
sizeof(
float)));
102 glEnableVertexAttribArray(1);
105 glBindVertexArray(0);
106 glBindBuffer(GL_ARRAY_BUFFER, 0);
108 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
111 glDepthFunc(GL_LEQUAL);
112 glEnable(GL_DEPTH_TEST);
117 glDisable(GL_CULL_FACE);
132 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
141 static unsigned init= 0;
142 static unsigned zinit= 0;
143 static unsigned replay= 0;
148 zinit= (zinit +1) %2;
155 printf(
"Zpre pass OFF\n");
162 draw(mesh, model, view, projection);
165 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffer);
168 glClearBufferData(GL_SHADER_STORAGE_BUFFER, GL_R32F, GL_RED, GL_FLOAT, &zero);
171 glBindImageTexture(0, texture, 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32UI);
174 glClearTexImage(texture, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, &zero);
180 glBindVertexArray(vao);
181 glUseProgram(program_record);
183 program_uniform(program_record,
"mvpMatrix", mvp);
184 program_uniform(program_record,
"mvMatrix", mv);
185 program_uniform(program_record,
"counters", 0);
187 glDrawArrays(GL_TRIANGLES, 0, n);
189 glMemoryBarrier( GL_ALL_BARRIER_BITS);
201 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
203 draw(repere,
Identity(), view, projection);
205 glBindVertexArray(vao_replay);
206 glUseProgram(program_replay);
208 program_uniform(program_replay,
"mvpMatrix", mvp);
213 glDrawArrays(GL_POINTS, 0, replay);
215 static unsigned points= 1;
230 static bool video=
false;
236 if(video)
printf(
"start video capture...\n");
237 else printf(
"stop video capture.\n");
259 GLuint program_record;
260 GLuint program_replay;
264int 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, const int samples=0)
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 & 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_fast(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)
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.