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 & HelpPrograms › Rendering text on transparent image
Page Index Toggle Pages: 1
Rendering text on transparent image (Read 2085 times)
Rendering text on transparent image
Jun 7th, 2010, 8:09am
 
Hello,

I would like to draw a text on a transparent image (buffer). I can set the buffer transparent, but when rendering, every letter of my text has no-alpha (i.e. alpha = 1.0) background.

My code is like this:
Code:

PGraphics txtBuff;
PFont font;

void setup() {
size(400, 200);
font = loadFont("somefont.vlw");
txtBuff = createGraphics(width, height, P3D);
}

void draw() {
background(255, 0, 0); // Red

txtBuff.beginDraw();
txtBuff.background(0, 0); // Black background, transparent
txtBuff.textFont(font, 48);
txtBuff.fill(0, 255, 0); // Green text
txtBuff.text("Hello, World!", 100, 100);
txtBuff.textFont(font, 40);
txtBuff.fill(0, 0, 255); // Blue text
txtBuff.text("Hello, World!", 100, 120);
txtBuff.endDraw();

image(txtBuff, 0, 0);
}


The result is a red background with the two texts over it, but the two text (which are correctly rendered one over the other), have a black background.

How can I preserve background transparency under the letters?

Thanks
~Ale
Re: Rendering text on transparent image
Reply #1 - Jun 7th, 2010, 8:47am
 
It works if you use the PGraphics in JAVA2D mode. Do you really need the P3D mode? You don't seem to use 3D.
Re: Rendering text on transparent image
Reply #2 - Jun 7th, 2010, 3:12pm
 
Yes, thanks. I also "discovered" this:
http://dev.processing.org/bugs/show_bug.cgi?id=641

which I didn't see in the documentation for createGraphics:
http://processing.org/reference/createGraphics_.html

I'm not using 3D now, but I will.

Until now I hacked this issue copy()ing doing the composition of text later, reading the background before rendering. Anyway it's a bit pointless Cheesy

Thanks!
Re: Rendering text on transparent image
Reply #3 - Jun 8th, 2010, 1:59am
 
For the record, it (recently) became bug 80: text characters showing up as opaque rectangles with createGraphics()
Re: Rendering text on transparent image
Reply #4 - Jun 8th, 2010, 6:57am
 
Off-Topic replies have been moved to this Topic.
Page Index Toggle Pages: 1