Alpha blending not working
in
Programming Questions
•
3 years ago
Hi, I'm having a problem getting alpha to work properly. I'm using P3D and manually setting alpha bits using audio levels. I'm using println to verify that the color has changing alpha bits but none of that affects what's drawn to the screen. I've searched and searched and tried putting the calls in every order I can imagine. So far, no luck. Hopefully someone here can help.
The alphize(); function first:
- void alphize() {
- opencv.read();
- opencv.flip(OpenCV.FLIP_HORIZONTAL);
- camImage = opencv.image();
- loadPixels();
- for (int i = 0; i < IMG_HEIGHT * IMG_WIDTH; i++) {
- currColor = camImage.pixels[i];
- //clear alpha channel since it comes in as FF:
- currColor = 0x00FFFFFF & currColor;
- pixels[i] = 0x00000000 | (vidFactor << 24) | currColor;
- }
- updatePixels();
- println(hex(pixels[1]) + " " + vidFactor + " " + hex(currColor));
- PImage maskImage = camImage.get();
- maskImage.mask(camImage);
- //camImage.mask(camImage);
- image(maskImage, 0, 0);
- }
The main program:
- import processing.video.*;
- import ddf.minim.analysis.*;
- import ddf.minim.*;
- import hypermedia.video.*;
- Minim minim;
- AudioInput in;
- OpenCV opencv;
- PImage bkgdImg;
- PImage trailsImg;
- PImage camImage;
- float audioAmp = 0.0;
- float sampleAmp;
- int numPixels;
- int[] backgroundPixels;
- int IMG_WIDTH = 640;
- int IMG_HEIGHT = 480;
- int COLOR_SPACE = OpenCV.RGB;
- int vidFactor = 1;
- color currColor;
- void setup() {
- size(IMG_WIDTH, IMG_HEIGHT, P3D);
- background(0);
- opencv = new OpenCV(this);
- minim = new Minim(this);
- minim.debugOn();
- in = minim.getLineIn(Minim.STEREO, 512);
- opencv.capture(IMG_WIDTH, IMG_HEIGHT);
- //trailsImg = new PImage(640, 480);
- bkgdImg = new PImage(640, 480);
- }
- void draw() {
- // AUDIO ANALYSIS
- audioAmp *= 0.8;
- for(int i = 0; i < in.bufferSize() - 1; i++) {
- sampleAmp = abs(in.mix.get(i));
- audioAmp += sampleAmp;
- vidFactor = int(audioAmp);
- }
- if(audioAmp > 255) {
- audioAmp = 255;
- }
- // VIDEO ANALYSIS
- alphize();
- blend(bkgdImg, 0, 0, 640, 480, 0, 0, 640, 480, SOFT_LIGHT);
- }
1