17GLuint
read_cubemap(
const int unit,
const char *filename,
const GLenum texel_type = GL_RGBA )
21 if(image.pixels.empty())
24 int w= image.width / 4;
25 int h= image.height / 3;
29 GLenum data_type= GL_UNSIGNED_BYTE;
30 if(image.channels == 3)
37 glGenTextures(1, &texture);
38 glActiveTexture(GL_TEXTURE0 + unit);
39 glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
43 struct {
int x, y; } faces[]= {
52 for(
int i= 0; i < 6; i++)
56 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X +i, 0,
58 data_format, data_type, face.data());
62 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
63 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
64 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
65 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
66 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
68 glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
71 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
74 printf(
" cubemap faces %dx%d\n", w, h);
92 m_texture= read_cubemap(0,
"gkit2_tutos/cubemap_debug_cross.png");
95 m_program_draw=
read_program(
"gkit2_tutos/draw_cubemap.glsl");
102 m_objet.bounds(pmin, pmax);
106 glGenVertexArrays(1, &m_vao);
108 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
111 glDepthFunc(GL_LEQUAL);
112 glEnable(GL_DEPTH_TEST);
123 glDeleteVertexArrays(1, &m_vao);
124 glDeleteTextures(1, &m_texture);
131 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
137 Transform mvp= projection * view * model;
140 Point camera_position= viewInv(
Point(0, 0, 0));
143 glUseProgram(m_program);
144 program_uniform(m_program,
"mvpMatrix", mvp);
145 program_uniform(m_program,
"modelMatrix", model);
146 program_uniform(m_program,
"camera_position", camera_position);
148 glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture);
149 program_uniform(m_program,
"texture0",
int(0));
152 m_objet.draw(m_program);
158 glUseProgram(m_program_draw);
159 glBindVertexArray(m_vao);
160 program_uniform(m_program_draw,
"invMatrix", inv);
161 program_uniform(m_program_draw,
"camera_position", camera_position);
163 glBindTexture(GL_TEXTURE_CUBE_MAP, m_texture);
164 program_uniform(m_program_draw,
"texture0",
int(0));
166 glDrawArrays(GL_TRIANGLES, 0, 3);
169 glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
171 glBindVertexArray(0);
177 reload_program(m_program_draw,
"gkit2_tutos/draw_cubemap.glsl");
179 reload_program(m_program,
"gkit2_tutos/cubemap.glsl");
188 printf(
"screenshot %d\n", calls);
197 GLuint m_program_draw;
203int 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.
void lookat(const Point ¢er, const float size)
observe le point center a une distance size.
Transform viewport() const
renvoie la transformation viewport actuelle. doit etre initialise par projection(width,...
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.
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.
Image flipY(const Image &image)
retourne l'image
Image flipX(const Image &image)
retourne l'image
ImageData read_image_data(const void *buffer, const unsigned size, const bool flipY)
charge les donnees d'un fichier png stocke en memoire. renvoie une image initialisee par defaut en ca...
Image copy(const Image &image, const unsigned xmin, const unsigned ymin, const unsigned width, const unsigned height)
renvoie un bloc de l'image
Transform Inverse(const Transform &m)
renvoie l'inverse de la matrice.
Transform Identity()
construit la transformation identite.
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes....
int screenshot(const char *filename)
enregistre le contenu de la fenetre dans un fichier. doit etre de type .png / .bmp
GLuint read_program(const char *filename, const char *definitions)
int program_print_errors(const GLuint program)
affiche les erreurs de compilation.
int release_program(const GLuint program)
detruit les shaders et le program.
stockage temporaire des donnees d'une image.
representation d'un point 3d.
GLuint read_cubemap(const int unit, const char *filename, const GLenum texel_type=GL_RGBA)
charge une image, decoupe les 6 faces et renvoie une texture cubemap.