17 w= std::max(1, w / 2);
18 h= std::max(1, h / 2);
32 glGenTextures(1, &texture);
33 glActiveTexture(GL_TEXTURE0 + unit);
34 glBindTexture(GL_TEXTURE_2D, texture);
37 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
38 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
39 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
40 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
43 glTexImage2D(GL_TEXTURE_2D, 0,
45 GL_RGBA, GL_FLOAT, im.
buffer());
48 glGenerateMipmap(GL_TEXTURE_2D);
59 glGenTextures(1, &texture);
60 glActiveTexture(GL_TEXTURE0 + unit);
61 glBindTexture(GL_TEXTURE_2D, texture);
64 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
65 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
66 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
67 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
72 case 1: format= GL_RED;
break;
73 case 2: format= GL_RG;
break;
74 case 3: format= GL_RGB;
break;
75 case 4: format= GL_RGBA;
break;
76 default: format= GL_RGBA;
82 case 1: type= GL_UNSIGNED_BYTE;
break;
83 case 4: type= GL_FLOAT;
break;
84 default: type= GL_UNSIGNED_BYTE;
88 glTexImage2D(GL_TEXTURE_2D, 0,
89 texel_type, im.width, im.height, 0,
90 format, type, im.buffer());
93 glGenerateMipmap(GL_TEXTURE_2D);
98 GLuint
read_texture(
const int unit,
const char *filename,
const GLenum texel_type )
110 glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
111 glReadBuffer(GL_BACK);
115 glGetIntegerv(GL_VIEWPORT, viewport);
118 ImageData image(viewport[2], viewport[3], 4);
119 glReadPixels(0, 0, image.width, image.height,
120 GL_RGBA, GL_UNSIGNED_BYTE, image.buffer());
131 sprintf(tmp,
"%s%04d.bmp", prefix,
id);
134 printf(
"capture frame '%s'...\n", tmp);
ImageData read_image_data(const char *filename)
charge les donnees d'un fichier png. renvoie une image initialisee par defaut en cas d'echec...
const void * buffer() const
renvoie un pointeur sur le stockage des couleurs des pixels.
stockage temporaire des donnees d'une image.
int write_image_data(ImageData &image, const char *filename)
enregistre des donnees dans un fichier png.
GLuint make_texture(const int unit, const Image &im, const GLenum texel_type)
GLuint read_texture(const int unit, const char *filename, const GLenum texel_type)
int capture(const char *prefix)
int miplevels(const int width, const int height)
renvoie le nombre de mipmap d'une image width x height.
int height() const
renvoie la hauteur de l'image.
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().
representation d'une image.
int width() const
renvoie la largeur de l'image.
int screenshot(const char *filename)
enregistre le contenu de la fenetre dans un fichier filename nom de l'image a ecrire. doit etre de type .png / .bmp