267
void IOpenGLBaseTexture::Save(const char* filename)
269
GLuint tex_id = GetOpenGLID();
270
glBindTexture(GL_TEXTURE_2D, tex_id);
274
#ifndef NUX_OPENGLES_20
275
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
276
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &height);
279
height = GetHeight();
282
if(!width || !height)
285
uint32_t* pixels = new uint32_t[width * height];
286
uint32_t* tmp = pixels;
288
#ifndef NUX_OPENGLES_20
289
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
292
glGenFramebuffers(1, &fbo);
293
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
294
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_id, 0);
295
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
296
glBindFramebuffer(GL_FRAMEBUFFER, 0);
297
glDeleteFramebuffers(1, &fbo);
301
if(!(fp = fopen(filename, "wb"))) {
302
fprintf(stderr, "Cannot open file: %s\n", filename);
306
fprintf(fp, "P6\n%d %d\n255\n", width, height);
308
int sz = width * height;
309
for(int i=0; i<sz; i++) {
310
uint32_t pix = *tmp++;
311
int r = (pix >> 16) & 0xff;
312
int g = (pix >> 8) & 0xff;
268
324
int GetTextureSize(IOpenGLBaseTexture *pTexture)