Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

Background shines through text?

$
0
0
Hi everyone,

I need a little help in Processing color theory and/or overlaying graphics!

In my sketch I have a half transparent text on a separat PGraphics. When I overlay this text onto an other
PGraphics with an opaque rectangle and finally overlay this PGraphics onto the main canvas, the background of the canvas shines through the text.

What I expected was that the half transparent text will be merged with the rectangle color and will get opaque and not that the opaque rectangle gets transparent with the overlayed text. It's as the text works like an alpha mask, but I don't want that.

What do I miss here? Or whats the right way to archive my expected result?

Thank you for your time!

My specs: Windows7 64bit, NVIDIA GeForce 560M, Processing 2.0b6



  1. package spheretest;
  2. import processing.core.PApplet;
  3. import processing.core.PGraphics;
  4. public class Main extends PApplet {
  5.     /**
  6.      *
  7.      */
  8.     private static final long serialVersionUID = 3655653701051264925L;
  9.     private PGraphics pg = null;
  10.     private PGraphics java2d = null;
  11.     public void setup() {
  12.         size(500, 500, P3D);
  13.         pg = createGraphics(width, height, P3D);
  14.         java2d = createGraphics(width, height, JAVA2D);
  15.        
  16.         java2d.beginDraw();
  17.         java2d.background(0, 0, 0, 0);
  18.         java2d.fill(0,0,0,150);
  19.         java2d.textSize(36);
  20.         java2d.text("Transparent Text", 50, 50);
  21.        
  22.         java2d.fill(0,0,0,100);
  23.         java2d.textSize(36);
  24.         java2d.text("Transparent Text", 50, 86);
  25.        
  26.         java2d.fill(0,0,0,50);
  27.         java2d.textSize(36);
  28.         java2d.text("Transparent Text", 50, 122);
  29.         java2d.endDraw();
  30.     }
  31.     public void draw() {
  32.        
  33.         background(255, 0, 0);
  34.         noStroke();
  35.         fill(0,255,0);
  36.         rect(50, 50, 400, 25);

  37.         pg.beginDraw();
  38.         pg.background(0, 0, 0, 0);
  39.         pg.noStroke();       
  40.         pg.fill(255);
  41.         pg.rect(0, 0, 200, 200);       
  42.         pg.image(java2d,0,0);
  43.         pg.endDraw();

  44.         image(pg, 0, 0);
  45.     }
  46.     public static void main(String args[]) {
  47.         PApplet.main(new String[] { spheretest.Main.class.getName() });
  48.     }
  49. }


Viewing all articles
Browse latest Browse all 1768

Trending Articles