X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbctexture.C;h=59e21810d50ba64ffd07c23ebb4ca240592b4d11;hb=7e5a0760f40ff787cc3d93cb7768a901ebe52809;hp=d9bc92d94869d67e314cc907d0495f3b8d16be27;hpb=235c9cc4df8306babbbfda46189108fe262d44ef;p=goodguy%2Fhistory.git diff --git a/cinelerra-5.1/guicast/bctexture.C b/cinelerra-5.1/guicast/bctexture.C index d9bc92d9..59e21810 100644 --- a/cinelerra-5.1/guicast/bctexture.C +++ b/cinelerra-5.1/guicast/bctexture.C @@ -33,7 +33,6 @@ BC_Texture::BC_Texture(int w, int h, int colormodel) this->h = h; this->colormodel = colormodel; texture_id = -1; - texture_id = -1; texture_w = 0; texture_h = 0; texture_components = 0; @@ -227,18 +226,34 @@ void BC_Texture::bind(int texture_unit) #endif } -void write_ppm(uint8_t *tp, int w, int h, const char *fmt, ...); +#ifdef HAVE_GL +static void write_ppm(uint8_t *tp, int w, int h, const char *fmt, ...) +{ + va_list ap; va_start(ap, fmt); + char fn[256]; vsnprintf(fn, sizeof(fn), fmt, ap); + va_end(ap); + FILE *fp = !strcmp(fn,"-") ? stdout : fopen(fn,"w"); + if( fp ) { + fprintf(fp,"P6\n%d %d\n255\n",w,h); + fwrite(tp,3*w,h,fp); + if( fp != stdout ) fclose(fp); + } +} +#endif void BC_Texture::write_tex(const char *fn) { #ifdef HAVE_GL int prev_id = -1; glGetIntegerv(GL_ACTIVE_TEXTURE, &prev_id); - glActiveTexture(this->texture_id); + glActiveTexture(GL_TEXTURE31); + glBindTexture(GL_TEXTURE_2D, texture_id); + glEnable(GL_TEXTURE_2D); int w = get_texture_w(), h = get_texture_h(); - uint8_t img[w*h*3]; + uint8_t *img = new uint8_t[w*h*3]; glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, img); write_ppm(img, w, h, "%s", fn); + delete img; glActiveTexture(prev_id); #endif }