We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpOpenGL and 3D Libraries › Probleme with alpha in GLGraphics OffScreen
Pages: 1 2 
Probleme with alpha in GLGraphics OffScreen (Read 4716 times)
Re: Probleme with alpha in GLGraphics OffScreen
Reply #15 - Dec 12th, 2009, 11:36am
 
Hello,
I have few more questions concerning GLGraphics

1] How it is possible to erase  GLGraphics or GLGraphicsOffScreen?
.getTexture().clear() does not work like I expected:

Code:

import processing.opengl.*;
import codeanticode.glgraphics.*;
import codeanticode.protablet.*;

GLGraphicsOffScreen buf;
GLTexture tex;

void setup()
{
size(600, 600, GLConstants.GLGRAPHICS);  
buf = new GLGraphicsOffScreen(this, width, height, true, 4);
tex = buf.getTexture();

 buf.beginDraw();
 
 // Paint what should be erased
 buf.fill(0,255);  
 buf.ellipse(100,100,50,50);

 //try to erase buf
 tex.setValue(0,0,0,0);
 tex.clear(0,0,0,0);
 
 buf.endDraw();

image(buf.getTexture(), 0, 0, width, height);
// Hey, die, you damn circle !!!
}

It does nothing. I think the trouble is that getTexture() return copy of GLgraphics texture not pointer to actual object. clear() clears "tex" but not content of buf.

2] Are render modes for setBlendMode() documented somewhere?
is it possible to activate aditive, substractive or maximum blend mode?
Isn't it possible just pass original opengl glBlendFunc(); and glBlendEquation() into GLGraphics?

3]Is there allready some functionality to set Alpha channel?
I'd like to use it for loading Brush stencils from Black&White pictures. (Use White as transparent and black as opaque)
Re: Probleme with alpha in GLGraphics OffScreen
Reply #16 - Dec 12th, 2009, 2:40pm
 
the problem is that doing tex.clear(0,0,0,0) inside buf.beginDraw()/buf.endDraw() is not good, because at that moment buf is using tex to write the result of the offscreen rendering. You shouldn't draw to tex while is being used by the renderer. You can clear tex afterwards:

Code:

import processing.opengl.*;
import codeanticode.glgraphics.*;
GLGraphicsOffScreen buf;
GLTexture tex;

void setup()
{
 size(600, 600, GLConstants.GLGRAPHICS);  
 buf = new GLGraphicsOffScreen(this, width, height, true, 4);
 tex = buf.getTexture();

 buf.beginDraw();
 buf.fill(0,255);  
 buf.ellipse(100,100,50,50);  
 buf.endDraw();
 tex.clear(0,0,0,0);
 image(buf.getTexture(), 0, 0, width, height);
}


2] and 3] will take some time...
Re: Probleme with alpha in GLGraphics OffScreen
Reply #17 - Dec 12th, 2009, 4:45pm
 
I'm very happy for your fast answer.
If I use gettexture().clear() outside beginDraw() ... endDraw() it clears something but picture resurect when I start drawing again. I don't understand this behaviour.

This code illustrate it:
Code:

import processing.opengl.*;
import codeanticode.glgraphics.*;
import codeanticode.protablet.*;

GLGraphicsOffScreen buf;
GLTexture tex;

void setup()
{
 size(600, 600, GLConstants.GLGRAPHICS);
 buf = new GLGraphicsOffScreen(this, width, height, true, 4);
 buf.beginDraw();
 buf.noStroke();
 buf.endDraw();
}

//set color of stroke
void mousePressed(){
 buf.beginDraw();
 buf.fill(random(255),random(255),random(255),128);
 buf.endDraw();
};


//paint the stroke
void mouseDragged(){
buf.beginDraw();
buf.ellipse(mouseX,mouseY,50,50);
buf.endDraw();
};

//clear the stroke from buffer buf
void mouseReleased(){
 buf.getTexture().clear(0,0,0,0);
};

void draw(){
//some strips as background
background(255,255);
stroke(0);
for(int i=0;i<width;i+=10){
line(i,0,i,height);
};
 
//view buffer buf
image(buf.getTexture(), 0, 0, width, height);
};


I hope the behaviour with your version of Glgraphics (I downloaded the glgraphics-20091116 you linked here) is the same as mine.

If you press mouse button and drag the mouse stroke is painted. When you release musebutton it should clear the buffer. Until you press the mouse again everything looks OK. But after the next stroke is started the old stroke returns form the hell.

Re: Probleme with alpha in GLGraphics OffScreen
Reply #18 - Dec 13th, 2009, 4:17am
 
An other question about how to copy one texture into each other, I didn't found anything like GLTexture.copy(GLTexture srcText). I don't want to use destTex.getImage() and srcTex.putImage() because I worry about slow down by main memory <-> Graphics card transfer.

I do it now by glsl filter like:
Code:


// copyis source texture to destination texture
cp = new GLTextureFilter(this, "copy.xml");
// makes hole arround mouse
myFilter = new GLTextureFilter(this, "MouseHole.xml");

....

   //mouse erraser
   float x = map(mouseX, 0, width, 0, srcTex.width);
   float y = map(mouseY, 0, height, 0, srcTex.height);
   myFilter.setParameterValue("mpos", new float[]{x, y});
   myFilter.setParameterValue("mdist", mouseDist);
   myFilter.apply(srcTex, destTex);
   
   //visualize
   image(destTex, 0, 0, width, height);
   
   //copy back to acumulate effect
   cp.apply(destTex, srcTex);



the whole code with source picture and *.glsl filters is here
http://nanosurf.fzu.cz/wiki/lib/exe/fetch.php?media=prokop:mousemole.zip

is there better method?
Re: Probleme with alpha in GLGraphics OffScreen
Reply #19 - Dec 13th, 2009, 6:57am
 
Hey, I found the problem with clearing the texture of the offscreen surface. It happens when you use antialising, because in that mode there are actually two color buffers used to render the offscreen image, one is the texture that you get with buf.getTexture(), but then there is another one used to generate the downsampling, which doesn't have public access. Doing buf.getTexture().clear(0, 0, 0, 0); only updates the former. So I added a GLGraphicsOffScreen.clear() method that take the same arguments as GLTexture.clear() but clears both buffers:

Code:

import processing.opengl.*;
import codeanticode.glgraphics.*;

GLGraphicsOffScreen buf;
GLTexture tex;

void setup() {
 size(600, 600, GLConstants.GLGRAPHICS);
 buf = new GLGraphicsOffScreen(this, width, height, true, 4);
 buf.beginDraw();
 buf.noStroke();
 buf.endDraw();
}

void mousePressed(){
 buf.beginDraw();
 buf.fill(random(255),random(255),random(255),128);
 buf.endDraw();
};

void mouseDragged(){
buf.beginDraw();
buf.ellipse(mouseX,mouseY,50,50);
buf.endDraw();
};

void mouseReleased(){
 buf.beginDraw();
 buf.clear(0, 0, 0, 0);
 buf.endDraw();  
};

void draw(){
//some strips as background
background(255,255);
stroke(0);
for(int i=0;i<width;i+=10){
line(i,0,i,height);
};
 
image(buf.getTexture(), 0, 0, width, height);
};


The copy texture method would also be a good addition to GLTexture, so I prepared this new version that incorporates GLGraphicsOffScreen.clear() and GLTexture.copy():

http://users.design.ucla.edu/~acolubri/processing/glgraphics/glgraphics-20091213.zip
Pages: 1 2