charge une image, decoupe les 6 faces et renvoie une texture cubemap.
18{
19
21 if(image.pixels.empty())
22 return 0;
23
24 int w= image.width / 4;
25 int h= image.height / 3;
26 assert(w == h);
27
28 GLenum data_format;
29 GLenum data_type= GL_UNSIGNED_BYTE;
30 if(image.channels == 3)
31 data_format= GL_RGB;
32 else
33 data_format= GL_RGBA;
34
35
36 GLuint texture= 0;
37 glGenTextures(1, &texture);
38 glActiveTexture(GL_TEXTURE0 + unit);
39 glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
40
41
42
43 struct { int x, y; } faces[]= {
44 {0, 1},
45 {2, 1},
46 {1, 2},
47 {1, 0},
48 {1, 1},
49 {3, 1},
50 };
51
52 for(int i= 0; i < 6; i++)
53 {
55
56 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X +i, 0,
57 texel_type, w, h, 0,
58 data_format, data_type, face.data());
59 }
60
61
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);
67
68 glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
69
70
71 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
72
73
74 printf(
" cubemap faces %dx%d\n", w, h);
75
76 return texture;
77}
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().
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
stockage temporaire des donnees d'une image.