X-Git-Url: https://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fguicast%2Fbctexture.C;h=e3eda5fa407fe4de9e5d8c2d26742fad9cb95872;hb=1b764a9134043e08d4ca6161a6ac58b105cc6b2b;hp=7cebeefc2f3d9b2b3dadf5c1034c2320702e41ad;hpb=7fd85fb66168f6b518c5f2d73e04036e87faa0e1;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/guicast/bctexture.C b/cinelerra-5.1/guicast/bctexture.C index 7cebeefc..e3eda5fa 100644 --- a/cinelerra-5.1/guicast/bctexture.C +++ b/cinelerra-5.1/guicast/bctexture.C @@ -100,8 +100,8 @@ void BC_Texture::create_texture(int w, int h, int colormodel) BC_WindowBase::get_synchronous()->release_texture( window_id, texture_id); - texture_id = -1; - window_id = -1; + texture_id = -1; + window_id = -1; } @@ -124,13 +124,9 @@ void BC_Texture::create_texture(int w, int h, int colormodel) glGenTextures(1, (GLuint*)&texture_id); glBindTexture(GL_TEXTURE_2D, (GLuint)texture_id); glEnable(GL_TEXTURE_2D); - if(texture_components == 4) - glTexImage2D(GL_TEXTURE_2D, 0, 4, texture_w, texture_h, + int internal_format = texture_components == 4 ? GL_RGBA8 : GL_RGB8 ; + glTexImage2D(GL_TEXTURE_2D, 0, internal_format, texture_w, texture_h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0); - else - glTexImage2D(GL_TEXTURE_2D, 0, 3, texture_w, texture_h, - 0, GL_RGB, GL_UNSIGNED_BYTE, 0); - window_id = BC_WindowBase::get_synchronous()->current_window->get_id(); BC_WindowBase::get_synchronous()->put_texture(texture_id, texture_w, texture_h, texture_components); @@ -200,7 +196,7 @@ void BC_Texture::draw_texture( #endif } -void BC_Texture::bind(int texture_unit) +void BC_Texture::bind(int texture_unit, int nearest) { #ifdef HAVE_GL // Bind the texture @@ -209,10 +205,10 @@ void BC_Texture::bind(int texture_unit) if(texture_unit >= 0) glActiveTexture(GL_TEXTURE0 + texture_unit); glBindTexture(GL_TEXTURE_2D, texture_id); glEnable(GL_TEXTURE_2D); - if(texture_unit >= 0) - { - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + if(texture_unit >= 0) { + int filter = nearest ? GL_NEAREST : GL_LINEAR; + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter); // GL_REPEAT in this case causes the upper left corners of the masks // to blur. @@ -241,21 +237,27 @@ static void write_ppm(uint8_t *tp, int w, int h, const char *fmt, ...) } #endif -void BC_Texture::write_tex(const char *fn) +void BC_Texture::write_tex(const char *fn, int id) { #ifdef HAVE_GL int prev_id = -1; glGetIntegerv(GL_ACTIVE_TEXTURE, &prev_id); - glActiveTexture(GL_TEXTURE31); + glActiveTexture(GL_TEXTURE0+id); glBindTexture(GL_TEXTURE_2D, texture_id); glEnable(GL_TEXTURE_2D); int w = get_texture_w(), h = get_texture_h(); 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; + delete [] img; glActiveTexture(prev_id); #endif } +void BC_Texture::write_tex(const char *fn) +{ +#ifdef HAVE_GL + write_tex(fn, 31); +#endif +}