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;
59 TP(
const char *filename ) :
AppCamera(1024, 640, 4, 3)
69 repere= make_grid(10);
71 if(mesh.vertex_count() == 0)
75 mesh.bounds(pmin, pmax);
79 n= mesh.vertex_count();
81 program_record=
read_program(
"gkit2_tutos/M2/fragment_record.glsl");
84 program_replay=
read_program(
"gkit2_tutos/M2/fragment.glsl");
90 glGenBuffers(1, &buffer);
91 glBindBuffer(GL_ARRAY_BUFFER, buffer);
92 glBufferData(GL_ARRAY_BUFFER, size * 6*
sizeof(
float),
nullptr, GL_DYNAMIC_DRAW);
98 glGenVertexArrays(1, &vao_replay);
100 glBindVertexArray(vao_replay);
101 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6*
sizeof(
float), (
const void *) (1*
sizeof(
unsigned)));
102 glEnableVertexAttribArray(0);
103 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 6*
sizeof(
float), (
const void *) (1*
sizeof(
unsigned) + 3*
sizeof(
float)));
104 glEnableVertexAttribArray(1);
107 glBindVertexArray(0);
108 glBindBuffer(GL_ARRAY_BUFFER, 0);
110 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
113 glDepthFunc(GL_LEQUAL);
114 glEnable(GL_DEPTH_TEST);
118 glEnable(GL_CULL_FACE);
133 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
142 static bool init=
false;
143 static bool zinit=
false;
144 static unsigned replay= 0;
155 printf(
"Z prepass off\n");
159 static bool cull=
true;
167 glEnable(GL_CULL_FACE);
169 glDisable(GL_CULL_FACE);
172 printf(
"face culling ON\n");
174 printf(
"face culling off\n");
177 static bool reload=
false;
178 static bool early_tests=
true;
179 static const char *early_tests_definition=
"";
183 early_tests= !early_tests;
188 early_tests_definition=
"#define EARLY_TESTS";
190 early_tests_definition=
"#undef EARLY_TESTS";
193 printf(
"early fragment tests ON\n");
195 printf(
"early fragment test off\n");
198 static bool store_vertices=
false;
199 static const char *store_vertices_definition=
"";
203 store_vertices= !store_vertices;
208 store_vertices_definition=
"#define STORE_VERTICES";
210 store_vertices_definition=
"#undef STORE_VERTICES";
213 printf(
"store vertices ON\n");
215 printf(
"store vertices off\n");
222 std::string definitions;
223 definitions.append(early_tests_definition).append(
"\n").append(store_vertices_definition);
225 reload_program(program_record, definitions.c_str());
234 draw(mesh, model, view, projection);
237 glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, buffer);
240 glClearBufferData(GL_SHADER_STORAGE_BUFFER, GL_R32F, GL_RED, GL_FLOAT, &zero);
243 glBindImageTexture(0, texture, 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32UI);
246 glClearTexImage(texture, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, &zero);
252 glBindVertexArray(vao);
253 glUseProgram(program_record);
255 program_uniform(program_record,
"mvpMatrix", mvp);
256 program_uniform(program_record,
"mvMatrix", mv);
257 program_uniform(program_record,
"counters", 0);
259 glDrawArrays(GL_TRIANGLES, 0, n);
261 glMemoryBarrier( GL_ALL_BARRIER_BITS);
270 if(zinit)
printf(
"Z prepass ON, ");
271 else printf(
"Z prepass off, ");
272 if(store_vertices)
printf(
"store vertices ON, ");
273 else printf(
"store vertices off, ");
274 if(cull)
printf(
"face culling ON, ");
275 else printf(
"face culling off, ");
276 if(early_tests)
printf(
"early fragment tests ON");
277 else printf(
"early fragment test off");
285 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
287 draw(repere,
Identity(), view, projection);
289 glBindVertexArray(vao_replay);
290 glUseProgram(program_replay);
292 program_uniform(program_replay,
"mvpMatrix", mvp);
297 glDrawArrays(GL_POINTS, 0, replay);
305 static unsigned points= 1;
320 static bool video=
false;
326 if(video)
printf(
"start video capture...\n");
327 else printf(
"stop video capture.\n");
349 GLuint program_record;
350 GLuint program_replay;
354int main(
int argc,
char **argv )
356 const char *filename=
"data/bigguy.obj";
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.
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.
bool window_resize()
renvoie vrai si la fenetre peut etre redimensionnee.
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.