24 StorageImage( ) :
AppTime(1024, 640, 4, 3) {}
31 m_mesh.bounds(pmin, pmax);
32 m_camera.lookat(pmin, pmax);
35 glGenTextures(1, &m_texture);
36 glBindTexture(GL_TEXTURE_2D, m_texture);
37 glTexImage2D(GL_TEXTURE_2D, 0,
39 GL_RED_INTEGER, GL_UNSIGNED_INT,
nullptr);
42 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
45 m_program=
read_program(
"gkit2_tutos/tuto_storage_texture.glsl");
48 m_program_display=
read_program(
"gkit2_tutos/storage_texture_display.glsl");
52 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
56 glEnable(GL_DEPTH_TEST);
60 glEnable(GL_CULL_FACE);
70 glDeleteTextures(1, &m_texture);
74 int update(
const float time,
const float delta )
83 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
87 glClearTexImage(m_texture, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, &zero);
90 update_camera( m_camera );
93 static bool cull=
true;
100 glEnable(GL_CULL_FACE);
102 glDisable(GL_CULL_FACE);
105 printf(
"face culling ON\n");
107 printf(
"face culling off\n");
111 static bool early_tests=
true;
112 static const char *early_tests_definition=
"";
113 static bool reload=
false;
118 early_tests= !early_tests;
120 early_tests_definition=
"#define EARLY_TESTS";
122 early_tests_definition=
"#undef EARLY_TESTS";
126 printf(
"early fragment tests ON\n");
128 printf(
"early fragment test off\n");
136 reload_program(m_program,
"gkit2_tutos/tuto_storage_texture.glsl", early_tests_definition);
139 reload_program(m_program_display,
"gkit2_tutos/storage_texture_display.glsl");
144 glUseProgram(m_program);
152 program_uniform(m_program,
"mvpMatrix", mvp);
155 glBindImageTexture(0, m_texture, 0, GL_TRUE, 0, GL_READ_WRITE, GL_R32UI);
156 program_uniform(m_program,
"image", 0);
158 m_mesh.draw(m_program);
163 glUseProgram(m_program_display);
166 glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
169 glBindImageTexture(0, m_texture, 0, GL_TRUE, 0, GL_READ_ONLY, GL_R32UI);
170 program_uniform(m_program_display,
"image", 0);
172 glDrawArrays(GL_TRIANGLES, 0, 3);
183 GLuint m_program_display;
188int main(
int argc,
char **argv )
AppTime(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.
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet.
int update(const float time, const float delta)
a deriver et redefinir pour animer les objets en fonction du temps.
int init()
a deriver pour creer les objets openGL.
int render()
a deriver pour afficher les objets.
int quit()
a deriver pour detruire les objets openGL.
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.
float global_time()
renvoie le temps ecoule depuis le lancement de l'application, en millisecondes.
Transform RotationY(const float a)
renvoie la matrice representation une rotation de a degree autour de l'axe Y.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
GLuint read_program(const char *filename, const char *definitions)
int program_print_errors(const GLuint program, const char *filename)
affiche les erreurs de compilation.
int release_program(const GLuint program)
detruit les shaders et le program.
representation d'un point 3d.