gKit2 light
Loading...
Searching...
No Matches
shader_kit_debug.cpp
1
3
4#include <cstdio>
5#include <cstring>
6
7#include <chrono>
8
9#include "glcore.h"
10#include "window.h"
11#include "files.h"
12
13#include "program.h"
14#include "uniforms.h"
15
16#include "texture.h"
17#include "mesh.h"
18#include "wavefront.h"
19
20#include "vec.h"
21#include "mat.h"
22#include "orbiter.h"
23
24#include "text.h"
25#include "widgets.h"
26
27
28// program
29const char *program_filename;
30GLuint program;
31
32// affichage des erreurs de compilation
33std::string program_log;
34int program_area;
35bool program_failed;
36
37// mesh, si charge...
38const char *mesh_filename;
39Mesh mesh;
40Point mesh_pmin;
41Point mesh_pmax;
42int vertex_count;
43
44GLuint vao;
45
46// textures
47std::vector<const char *> texture_filenames;
48std::vector<GLuint> textures;
49
50// affichage
51bool wireframe= false;
52int debug= 0;
53int debug_capture= 0;
54int debug_mode= 1;
55
56// camera
57Orbiter mesh_camera;
58
59// ui
60Widgets widgets;
61
62// mode debug
63GLuint debug_framebuffer= 0;
64GLuint debug_color;
65GLuint debug_depth;
66GLuint debug_position;
67GLuint debug_normal;
68GLuint debug_data;
69
70GLuint debug_program= 0;
71GLuint debug_wireframe_program= 0;
72
73Orbiter debug_camera;
74Transform debug_mvpi_inv;
75
76
77GLuint make_debug_framebuffer( const int w, const int h )
78{
79 glGenFramebuffers(1, &debug_framebuffer);
80 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, debug_framebuffer);
81
82 debug_depth= make_depth_texture(0, w, h);
83 debug_color= make_vec4_texture(0, w, h);
84 debug_position= make_vec4_texture(0, w, h);
85 debug_normal= make_vec4_texture(0, w, h);
86 debug_data= make_vec4_texture(0, w, h);
87
88 glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, debug_depth, /* mipmap */ 0);
89 glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, debug_color, /* mipmap */ 0);
90 glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, debug_position, /* mipmap */ 0);
91 glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, debug_normal, /* mipmap */ 0);
92 glFramebufferTexture(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, debug_data, /* mipmap */ 0);
93
94 GLenum buffers[]= { GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2, GL_COLOR_ATTACHMENT3 };
95 glDrawBuffers(4, buffers);
96
97 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
98 glBindTexture(GL_TEXTURE_2D, 0);
99
100 return debug_framebuffer;
101}
102
103void clear_debug_framebuffer( )
104{
105 float one[]= { 1 };
106 glClearBufferfv(GL_DEPTH, 0, one);
107
108 float zero[]= { 0, 0, 0, 0 };
109 glClearBufferfv(GL_COLOR, 0, zero);
110 glClearBufferfv(GL_COLOR, 1, zero);
111 glClearBufferfv(GL_COLOR, 2, zero);
112 glClearBufferfv(GL_COLOR, 3, zero);
113}
114
115void release_debug_framebuffer( )
116{
117 glDeleteTextures(1, &debug_depth);
118 glDeleteTextures(1, &debug_color);
119 glDeleteTextures(1, &debug_position);
120 glDeleteTextures(1, &debug_normal);
121 glDeleteTextures(1, &debug_data);
122 glDeleteFramebuffers(1, &debug_framebuffer);
123}
124
125
126vec4 read_debug( const int x, const int y, const GLenum attach )
127{
128 glReadBuffer(attach);
129
130 vec4 tmp[16];
131 glReadPixels(x - 2, y - 2, 4, 4, GL_RGBA, GL_FLOAT, tmp);
132
133 // trouver un pixel avec des donnees
134 for(int i= 0; i < 16; i++)
135 if(tmp[i].x || tmp[i].y || tmp[i].z || tmp[i].w)
136 return tmp[i];
137
138 return vec4(0, 0, 0, 0);
139}
140
141vec4 read_debug_color( const int x, const int y )
142{
143 return read_debug(x, y, GL_COLOR_ATTACHMENT0);
144}
145vec4 read_debug_position( const int x, const int y )
146{
147 return read_debug(x, y, GL_COLOR_ATTACHMENT1);
148}
149vec4 read_debug_normal( const int x, const int y )
150{
151 return read_debug(x, y, GL_COLOR_ATTACHMENT2);
152}
153vec4 read_debug_data( const int x, const int y )
154{
155 return read_debug(x, y, GL_COLOR_ATTACHMENT3);
156}
157
158float read_depth( const int x, const int y )
159{
160 glReadBuffer(GL_BACK);
161
162 float tmp[16];
163 glReadPixels(x - 2, y - 2, 4, 4, GL_DEPTH_COMPONENT, GL_FLOAT, tmp);
164
165 // trouver un pixel avec des donnees
166 for(int i= 0; i < 16; i++)
167 if(tmp[i] != 1) // si zbufffer == 1, pas de geometrie dessinee sur le pixel...
168 return tmp[i];
169
170 return -1;
171}
172
173// application
174size_t last_load= 0;
175void reload_program( )
176{
177 if(program == 0)
178 program= read_program(program_filename);
179 else
180 reload_program(program, program_filename);
181
182 // conserve la date du fichier
183 last_load= timestamp(program_filename);
184
185 // recupere les erreurs, si necessaire
186 program_area= program_format_errors(program, program_log);
187
188 if(program_log.size() > 0)
189 printf("[boom]\n%s\n", program_log.c_str());
190
191 program_failed= (program_log.size() > 0);
192}
193
194
195// cherche un fichier avec l'extension ext dans les options
196const char *option_find( std::vector<const char *>& options, const char *ext )
197{
198 for(unsigned int i= 0; i < (unsigned int) options.size() ; i++)
199 {
200 if(options[i] != nullptr && std::string(options[i]).rfind(ext) != std::string::npos)
201 {
202 const char *option= options[i];
203 options[i]= nullptr;
204 return option;
205 }
206 }
207
208 return nullptr;
209}
210
213int init( std::vector<const char *>& options )
214{
215 widgets= create_widgets();
216 mesh_camera= Orbiter();
217
218 program= 0;
219 const char *option;
220 option= option_find(options, ".glsl");
221 if(option != nullptr)
222 {
223 program_filename= option;
224 reload_program();
225 }
226
227 vao= 0;
228 mesh_pmin= Point(normalize(Vector(-1, -1, 0)) * 2.5f);
229 mesh_pmax= Point(normalize(Vector( 1, 1, 0)) * 2.5f);
230
231 option= option_find(options, ".obj");
232 if(option != nullptr)
233 {
234 mesh= read_mesh(option);
235 if(mesh.vertex_count() > 0)
236 {
237 mesh_filename= option;
238
239 vao= mesh.create_buffers(mesh.has_texcoord(), mesh.has_normal(), mesh.has_color(), mesh.has_material_index());
240 vertex_count= mesh.vertex_count();
241
242 mesh.bounds(mesh_pmin, mesh_pmax);
243 mesh_camera.lookat(mesh_pmin, mesh_pmax);
244 }
245
246 // ou generer une erreur ?
247 }
248
249 if(vao == 0)
250 {
251 glGenVertexArrays(1, &vao);
252 vertex_count= 3;
253 }
254
255 // charge les textures, si necessaire
256 for(int i= 0; i < int(options.size()); i++)
257 {
258 if(options[i] == nullptr)
259 continue;
260
261 GLuint texture= read_texture(0, options[i]);
262 if(texture > 0)
263 {
264 texture_filenames.push_back(options[i]);
265 textures.push_back(texture);
266 }
267 }
268
269 // debug
270 debug_wireframe_program= read_program( smart_path("data/shaders/debug_wireframe.glsl") );
271 program_print_errors(debug_wireframe_program);
272 debug_program= read_program( smart_path("data/shaders/debug.glsl") );
273 program_print_errors(debug_program);
274 make_debug_framebuffer(window_width(), window_height());
275
276 // nettoyage
277 glUseProgram(0);
278 glBindTexture(GL_TEXTURE_2D, 0);
279 glBindVertexArray(0);
280 glBindBuffer(GL_ARRAY_BUFFER, 0);
281 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
282
283 // etat openGL par defaut
284 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
285 glClearDepth(1.f);
286
287 glCullFace(GL_BACK);
288 glFrontFace(GL_CCW);
289 //~ glEnable(GL_CULL_FACE); // n'affiche que les faces correctement orientees...
290 glDisable(GL_CULL_FACE); // les faces mal orientees sont affichees avec des hachures oranges...
291
292 glDepthFunc(GL_LESS);
293 glEnable(GL_DEPTH_TEST);
294
295 return 0;
296}
297
298int quit( )
299{
300 // detruit les objets openGL
301 release_widgets(widgets);
302 release_program(program);
303 mesh.release();
304
305 glDeleteTextures(textures.size(), textures.data());
306 return 0;
307}
308
309int draw( void )
310{
311 // active / desactive le mode debug
312 if(key_state('d'))
313 {
314 clear_key_state('d');
315 debug= (debug +1) %2;
316
317 if(debug)
318 {
319 // capture le rendu...
320 debug_capture= 1;
321 debug_camera= mesh_camera;
322 }
323 else
324 mesh_camera= debug_camera;
325 }
326
327 if(wireframe && !debug)
328 {
329 //~ glClearColor(1, 1, 1, 1);
330 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
331 glLineWidth(2);
332 }
333 else
334 {
335 //~ glClearColor(0.2f, 0.2f, 0.2f, 1);
336 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
337 }
338
339 // effacer l'image
340 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
341
342 // verification de la date du fichier source des shaders...
343 static float last_time= 0;
344 // toutes les secondes, ca suffit, pas tres malin de le faire 60 fois par seconde...
345 if(global_time() > last_time + 400)
346 {
347 if(timestamp(program_filename) != last_load)
348 {
349 // date modifiee, recharger les sources et recompiler...
350 reload_program();
351
352 // capture l'execution de la nouvelle version du shader...
353 if(debug)
354 debug_capture= 1;
355 }
356
357 // attends le chargement et la compilation des shaders... au cas ou ce soit plus long qu'une seconde...
358 // (oui ca arrive...)
359 last_time= global_time();
360 }
361
362 if(key_state('r'))
363 {
364 clear_key_state('r');
365 reload_program();
366 }
367
368 // controle camera
369 Orbiter& camera= debug ? debug_camera : mesh_camera;
370
371 // recupere les mouvements de la souris
372 int mx, my;
373 unsigned int mb= SDL_GetRelativeMouseState(&mx, &my);
374 int mousex, mousey;
375 SDL_GetMouseState(&mousex, &mousey);
376
377 // deplace la camera
378 if(mb & SDL_BUTTON(1))
379 camera.rotation(mx, my); // tourne autour de l'objet
380 else if(mb & SDL_BUTTON(3))
381 camera.translation((float) mx / (float) window_width(), (float) my / (float) window_height()); // deplace le point de rotation
382 else if(mb & SDL_BUTTON(2))
383 camera.move(mx); // approche / eloigne l'objet
384
385 SDL_MouseWheelEvent wheel= wheel_event();
386 if(wheel.y != 0)
387 {
389 camera.move(8.f * wheel.y); // approche / eloigne l'objet
390 }
391
392 // etat
393 static float time= 0;
394 static int frame= 0;
395 static int video= 0;
396 static int freeze= 0;
397 static int reset_camera= 0;
398 static int copy_camera= 0;
399 static int paste_camera= 0;
400
401 // recupere les transformations
402 Transform model= Identity();
403 Transform view= camera.view();
404 Transform projection= camera.projection(window_width(), window_height(), 45);
406
407 Transform mvp= projection * view * model;
408 Transform mvpInv= Inverse(mvp);
409 Transform mv= model * view;
410
411 // temps
412 if(key_state('t'))
413 {
414 clear_key_state('t');
415 freeze= (freeze+1) % 2;
416 }
417 if(freeze == 0)
418 time= global_time();
419
420 // affiche l'objet, ou pas si le shader n'est pas compile...
421 if(!program_failed)
422 {
423 if(key_state('w'))
424 {
425 clear_key_state('w');
426 wireframe= !wireframe;
427 }
428
429 if(debug && !debug_capture)
430 {
431 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
432 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
433
434 glBindVertexArray(vao);
435 glUseProgram(debug_program);
436
437 int mode= debug_mode;
438 if(debug_mode == 4) // triangles
439 mode= 1; // affiche la couleur en plus de dessiner les triangles...
440 program_uniform(debug_program, "mode", mode);
441
442 program_uniform(debug_program, "viewport", vec2(window_width(), window_height()));
443 program_uniform(debug_program, "mvpMatrix", mvp * debug_mvpi_inv);
444 program_uniform(debug_program, "mvMatrix", mv * debug_mvpi_inv);
445
446 program_use_texture(debug_program, "zbuffer", 0, debug_depth);
447 program_use_texture(debug_program, "color", 1, debug_color);
448 program_use_texture(debug_program, "position", 2, debug_position);
449 program_use_texture(debug_program, "normal", 3, debug_normal);
450 program_use_texture(debug_program, "data", 4, debug_data);
451
452 glPointSize(3.5f);
453 glDrawArrays(GL_POINTS, 0, window_width() * window_height());
454
455 if(debug_mode == 4)
456 {
457 // dessine aussi les aretes des triangles
458 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
459
460 glUseProgram(debug_wireframe_program);
461 program_uniform(debug_wireframe_program, "mvpMatrix", mvp);
462
463 glLineWidth(2);
464 glDrawArrays(GL_TRIANGLES, 0, vertex_count);
465 }
466 }
467 else
468 {
469 if(debug_capture)
470 {
471 debug_capture= 0; // une seule capture suffit...
472
473 // prepare le debug
474 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, debug_framebuffer);
475 clear_debug_framebuffer();
476
477 debug_mvpi_inv= Inverse(viewport * mvp);
478 }
479
480 glBindVertexArray(vao);
481 glUseProgram(program);
482
483 // affecte une valeur aux uniforms
484 // transformations standards
485 program_uniform(program, "modelMatrix", model);
486 program_uniform(program, "modelInvMatrix", model.inverse());
487 program_uniform(program, "viewMatrix", view);
488 program_uniform(program, "viewInvMatrix", view.inverse());
489 program_uniform(program, "projectionMatrix", projection);
490 program_uniform(program, "projectionInvMatrix", projection.inverse());
491 program_uniform(program, "viewportMatrix", viewport);
492 program_uniform(program, "viewportInvMatrix", viewport.inverse());
493
494 program_uniform(program, "mvpMatrix", mvp);
495 program_uniform(program, "mvpInvMatrix", mvpInv);
496
497 program_uniform(program, "mvMatrix", mv);
498 program_uniform(program, "mvInvMatrix", mv.inverse());
499 program_uniform(program, "normalMatrix", mv.normal());
500
501 // interactions
502 program_uniform(program, "viewport", vec2(window_width(), window_height()));
503 program_uniform(program, "time", time);
504 program_uniform(program, "motion", vec3(mx, my, mb & SDL_BUTTON(1)));
505 program_uniform(program, "mouse", vec3(mousex, window_height() - mousey -1, mb & SDL_BUTTON(1)));
506
507 // textures
508 for(int i= 0; i < int(textures.size()); i++)
509 {
510 char uniform[1024];
511 sprintf(uniform, "texture%d", i);
512 program_use_texture(program, uniform, i, textures[i]);
513 }
514
515 // go
516 glDrawArrays(GL_TRIANGLES, 0, vertex_count);
517 }
518 }
519
520
521 // affiche les infos...
522 glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
523 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
524
525 begin(widgets);
526 if(program_failed)
527 {
528 // interface erreurs...
529 label(widgets, "[error] program '%s'", program_filename);
530 begin_line(widgets);
531 text_area(widgets, 20, program_log.c_str(), program_area);
532 }
533 else if(debug)
534 {
535 // interface debug...
536 button(widgets, "[d] debug", debug);
537
538 // reprojette le pixel sous la souris dans le point de vue capture...
539 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
540 float x= mousex + 0.5f;
541 float y= window_height() - mousey -1 + 0.5f;
542 float z= read_depth(x, y);
543 if(z > 0)
544 {
545 Transform m= Inverse(viewport * mvp * debug_mvpi_inv);
546 Point debug_fragment= m( Point(x, y, z) );
547
548 // relit les infos du fragment...
549 glBindFramebuffer(GL_READ_FRAMEBUFFER, debug_framebuffer);
550 vec4 position= read_debug_position(debug_fragment.x, debug_fragment.y);
551 vec4 color= read_debug_color(debug_fragment.x, debug_fragment.y);
552 vec4 normal= read_debug_normal(debug_fragment.x, debug_fragment.y);
553 vec4 data= read_debug_data(debug_fragment.x, debug_fragment.y);
554
555 begin_line(widgets);
556 label(widgets, "debug (%f, %f, %f)", x, y, z);
557
558 begin_line(widgets);
559 select(widgets, "draw position", 0, debug_mode);
560 label(widgets, "(%f, %f, %f, %f)", position.x, position.y, position.z, position.w);
561
562 begin_line(widgets);
563 select(widgets, "draw color ", 1, debug_mode);
564 label(widgets, "(%f, %f, %f, %f)", color.x, color.y, color.z, color.w);
565
566 begin_line(widgets);
567 select(widgets, "draw normal ", 2, debug_mode);
568 label(widgets, "(%f, %f, %f)", normal.x, normal.y, normal.z);
569
570 begin_line(widgets);
571 select(widgets, "draw data ", 3, debug_mode);
572 label(widgets, "(%f, %f, %f, %f)", data.x, data.y, data.z, data.w);
573
574 begin_line(widgets);
575 select(widgets, "draw triangles", 4, debug_mode);
576
577 // copie une vignette de la capture...
578 glReadBuffer(GL_COLOR_ATTACHMENT0);
579 glBlitFramebuffer(debug_fragment.x -16, debug_fragment.y -16, debug_fragment.x +16, debug_fragment.y +16,
581 GL_COLOR_BUFFER_BIT, GL_NEAREST);
582 }
583 else // pas de capture sur le pixel
584 {
585 begin_line(widgets);
586 label(widgets, "debug (%f, %f)", x, y);
587
588 begin_line(widgets);
589 select(widgets, "draw position", 0, debug_mode);
590
591 begin_line(widgets);
592 select(widgets, "draw color ", 1, debug_mode);
593
594 begin_line(widgets);
595 select(widgets, "draw normal ", 2, debug_mode);
596
597 begin_line(widgets);
598 select(widgets, "draw data ", 3, debug_mode);
599
600 begin_line(widgets);
601 select(widgets, "draw triangles", 4, debug_mode);
602 }
603 }
604 else
605 {
606 // interface standard...
607 button(widgets, "[d] debug", debug);
608 button(widgets, "[s] screenshot ", frame);
609 button(widgets, "capture frames", video);
610
611 begin_line(widgets);
612 button(widgets, "[t] freeze time", freeze);
613 button(widgets, "[f] reset camera", reset_camera);
614 button(widgets, "[c] copy/save camera", copy_camera);
615 button(widgets, "[v] paste/read camera", paste_camera);
616
617 begin_line(widgets);
618 begin_line(widgets);
619 label(widgets, "program '%s' running...", program_filename);
620 if(mesh_filename && mesh_filename[0])
621 {
622 begin_line(widgets);
623 label(widgets, "mesh '%s', %d vertices %s %s", mesh_filename, mesh.vertex_count(),
624 mesh.texcoord_buffer_size() ? "texcoords" : "", mesh.normal_buffer_size() ? "normals" : "");
625 }
626 for(unsigned int i= 0; i < (unsigned int) texture_filenames.size(); i++)
627 {
628 begin_line(widgets);
629 label(widgets, "texture%u '%s'", i, texture_filenames[i]);
630 }
631 }
632 end(widgets);
633
634 draw(widgets, window_width(), window_height());
635
636 if(frame || key_state('s'))
637 {
638 frame= 0;
639 clear_key_state('s');
640
641 static int calls= 1;
642 printf("screenshot %d...\n", calls);
643 screenshot("shader_kit", calls++);
644 }
645
646 if(video)
647 capture("shader_kit");
648
649 if(copy_camera || key_state('c'))
650 {
651 copy_camera= 0;
652 clear_key_state('c');
653 camera.write_orbiter("orbiter.txt");
654 }
655 if(paste_camera || key_state('v'))
656 {
657 paste_camera= 0;
658 clear_key_state('v');
659 if(camera.read_orbiter("orbiter.txt") < 0)
660 {
661 camera= Orbiter();
662 camera.lookat(mesh_pmin, mesh_pmax);
663 }
664 }
665
666 if(reset_camera || key_state('f'))
667 {
668 reset_camera= 0;
669 clear_key_state('f');
670
671 camera= Orbiter();
672 camera.lookat(mesh_pmin, mesh_pmax);
673 }
674
675 return 1;
676}
677
678
679int main( int argc, char **argv )
680{
681 if(argc == 1)
682 {
683 printf("usage: %s shader.glsl [mesh.obj] [texture0.png [texture1.png]]\n", argv[0]);
684 return 0;
685 }
686
687 Window window= create_window(1024, 640);
688 if(window == nullptr)
689 return 1;
690
691 Context context= create_context(window);
692 if(context == nullptr)
693 return 1;
694
695 // creation des objets opengl
696 std::vector<const char *> options(argv + 1, argv + argc);
697 if(init(options) < 0)
698 {
699 printf("[error] init failed.\n");
700 return 1;
701 }
702
703 // affichage de l'application
704 run(window, draw);
705
706 // nettoyage
707 quit();
708 release_context(context);
709 release_window(window);
710 return 0;
711}
representation d'un objet / maillage.
Definition mesh.h:121
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
Definition orbiter.h:17
const char * smart_path(const char *filename)
renvoie le chemin(path) vers le fichier 'filename' apres l'avoir cherche dans un repertoire standard....
Definition window.cpp:413
void begin(Widgets &w)
debut de la description des elements de l'interface graphique.
Definition widgets.cpp:29
Widgets create_widgets()
cree une interface graphique. a detruire avec release_widgets( ).
Definition widgets.cpp:12
void release_widgets(Widgets &w)
detruit l'interface graphique.
Definition widgets.cpp:23
Context create_context(Window window)
cree et configure un contexte opengl
Definition window.cpp:344
bool button(Widgets &w, const char *text, int &status)
Definition widgets.cpp:155
int window_height()
renvoie la hauteur de la fenetre de l'application.
Definition window.cpp:27
void release_window(Window window)
destruction de la fenetre.
Definition window.cpp:314
int run(Window window, int(*draw)())
boucle de gestion des evenements de l'application.
Definition window.cpp:145
void clear_key_state(const SDL_Keycode key)
desactive une touche du clavier.
Definition window.cpp:46
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().
Definition text.cpp:140
bool select(Widgets &w, const char *text, const int option, int &status)
Definition widgets.cpp:173
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.
Definition window.cpp:249
void release_context(Context context)
detruit le contexte openGL.
Definition window.cpp:404
void clear_wheel_event()
desactive l'evenement.
Definition window.cpp:114
int key_state(const SDL_Keycode key)
renvoie l'etat d'une touche du clavier. cf la doc SDL2 pour les codes.
Definition window.cpp:40
void text_area(Widgets &w, const int height, const char *text, int &begin_line)
Definition widgets.cpp:273
void begin_line(Widgets &w)
place les prochains elements sur une nouvelle ligne.
Definition widgets.cpp:129
SDL_MouseWheelEvent wheel_event()
renvoie le dernier evenement. etat de la molette de la souris / glisser sur le pad.
Definition window.cpp:110
int window_width()
renvoie la largeur de la fenetre de l'application.
Definition window.cpp:23
float global_time()
renvoie le temps ecoule depuis le lancement de l'application, en millisecondes.
Definition window.cpp:126
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
Definition mat.cpp:197
Transform Viewport(const float width, const float height)
renvoie la matrice representant une transformation viewport.
Definition mat.cpp:357
Transform Identity()
construit la transformation identite.
Definition mat.cpp:187
Vector normalize(const Vector &v)
renvoie un vecteur unitaire / longueur == 1.
Definition vec.cpp:167
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
Definition wavefront.cpp:14
int capture(const char *prefix)
Definition texture.cpp:205
int screenshot(const char *filename)
enregistre le contenu de la fenetre dans un fichier. doit etre de type .png / .bmp
Definition texture.cpp:178
GLuint read_program(const char *filename, const char *definitions)
Definition program.cpp:218
GLuint make_vec4_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).
Definition texture.cpp:171
int program_print_errors(const GLuint program)
affiche les erreurs de compilation.
Definition program.cpp:446
int release_program(const GLuint program)
detruit les shaders et le program.
Definition program.cpp:225
void program_use_texture(const GLuint program, const char *uniform, const int unit, const GLuint texture, const GLuint sampler)
configure le pipeline et le shader program pour utiliser une texture, et des parametres de filtrage,...
Definition uniforms.cpp:198
GLuint read_texture(const int unit, const char *filename, const GLenum texel_type)
Definition texture.cpp:133
int program_format_errors(const GLuint program, std::string &errors)
renvoie les erreurs de compilation.
Definition program.cpp:380
GLuint make_depth_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).
Definition texture.cpp:146
int init(std::vector< const char * > &options)
representation d'un point 3d.
Definition vec.h:21
representation d'une transformation, une matrice 4x4, organisee par ligne / row major.
Definition mat.h:21
Transform normal() const
renvoie la transformation a appliquer aux normales d'un objet transforme par la matrice m.
Definition mat.cpp:181
Transform inverse() const
renvoie l'inverse de la matrice.
Definition mat.cpp:399
representation d'un vecteur 3d.
Definition vec.h:67
vecteur generique, utilitaire.
Definition vec.h:152
vecteur generique, utilitaire.
Definition vec.h:169
vecteur generique 4d, ou 3d homogene, utilitaire.
Definition vec.h:192