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);
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);
116 glEnable(GL_CULL_FACE);
131 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
140 static bool init=
false;
141 static bool zinit=
false;
142 static unsigned replay= 0;
153 printf(
"Z prepass off\n");
157 static bool cull=
true;
164 glEnable(GL_CULL_FACE);
166 glDisable(GL_CULL_FACE);
169 printf(
"face culling ON\n");
171 printf(
"face culling off\n");
174 static bool early_tests=
true;
175 static const char *early_tests_definition=
"";
180 early_tests= !early_tests;
182 early_tests_definition=
"#define EARLY_TESTS";
184 early_tests_definition=
"#undef EARLY_TESTS";
187 printf(
"early fragment tests ON\n");
189 printf(
"early fragment test off\n");
191 reload_program(program_record,
"gkit2_tutos/M2/fragment_record.glsl", early_tests_definition);
199 draw(mesh, model, view, projection);
202 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffer);
205 glClearBufferData(GL_SHADER_STORAGE_BUFFER, GL_R32F, GL_RED, GL_FLOAT, &zero);
208 glBindImageTexture(0, texture, 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32UI);
211 glClearTexImage(texture, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, &zero);
217 glBindVertexArray(vao);
218 glUseProgram(program_record);
220 program_uniform(program_record,
"mvpMatrix", mvp);
221 program_uniform(program_record,
"mvMatrix", mv);
222 program_uniform(program_record,
"counters", 0);
224 glDrawArrays(GL_TRIANGLES, 0, n);
226 glMemoryBarrier( GL_ALL_BARRIER_BITS);
235 if(zinit)
printf(
"Z prepass ON, ");
236 else printf(
"Z prepass off, ");
237 if(cull)
printf(
"face culling ON, ");
238 else printf(
"face culling off, ");
239 if(early_tests)
printf(
"early fragment tests ON");
240 else printf(
"early fragment test off");
248 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
250 draw(repere,
Identity(), view, projection);
252 glBindVertexArray(vao_replay);
253 glUseProgram(program_replay);
255 program_uniform(program_replay,
"mvpMatrix", mvp);
260 glDrawArrays(GL_POINTS, 0, replay);
268 static unsigned points= 1;
283 static bool video=
false;
289 if(video)
printf(
"start video capture...\n");
290 else printf(
"stop video capture.\n");
312 GLuint program_record;
313 GLuint program_replay;
317int 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 & 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....
@ USE_POSITION
inclut l'attribut position dans les buffers.
int capture(const char *prefix)
GLuint read_program(const char *filename, const char *definitions)
int program_print_errors(const GLuint program, const char *filename)
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.