olaf neophyte and de.po updates, valgrind tweaks, delete green lady, inkscape dpi=96
[goodguy/history.git] / cinelerra-5.1 / guicast / bctexture.C
index 1ecbfd35c856b9271b6ed6ce51e852b32a9185da..7cebeefc2f3d9b2b3dadf5c1034c2320702e41ad 100644 (file)
@@ -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;
@@ -186,6 +185,21 @@ int BC_Texture::get_window_id()
 }
 
 
+void BC_Texture::draw_texture(
+       float in_x1, float in_y1, float in_x2, float in_y2,
+       float out_x1, float out_y1, float out_x2, float out_y2)
+{
+#ifdef HAVE_GL
+       glBegin(GL_QUADS);
+       glNormal3f(0, 0, 1.0);
+       glTexCoord2f(in_x1, in_y1);   glVertex3f(out_x1, out_y1, 0);
+       glTexCoord2f(in_x2, in_y1);   glVertex3f(out_x2, out_y1, 0);
+       glTexCoord2f(in_x2, in_y2);   glVertex3f(out_x2, out_y2, 0);
+       glTexCoord2f(in_x1, in_y2);   glVertex3f(out_x1, out_y2, 0);
+       glEnd();
+#endif
+}
+
 void BC_Texture::bind(int texture_unit)
 {
 #ifdef HAVE_GL
@@ -202,8 +216,8 @@ void BC_Texture::bind(int texture_unit)
 
 // GL_REPEAT in this case causes the upper left corners of the masks
 // to blur.
-                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
-                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+                       glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 
 // Get the texture to alpha blend
                        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
@@ -212,3 +226,36 @@ void BC_Texture::bind(int texture_unit)
 #endif
 }
 
+#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(GL_TEXTURE31);
+       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;
+       glActiveTexture(prev_id);
+#endif
+}
+
+