Hi everyone.
I'm trying create a stack of planes and then map a distinct image as texture on each of them. This is intended to recreate 3D from anatomic 2D slices.
Anyhow, when I assign the texture to the plane, the alpha channel seems to be available only on one side of the plane.
Does anyone knows how I could get alpha to work on both sides?
Code:
import processing.opengl.*;
PImage[] images_ar, masks_ar;
int bodyDef;
void setup()
{
size(320, 240, OPENGL);
framerate(25);
colorMode(HSB, 100);
rectMode(CENTER);
noStroke();
bodyDef = 165 / 5;
images_ar = new PImage[bodyDef];
masks_ar = new PImage[bodyDef];
String index;
for (int i = 0; i < bodyDef; i++) {
index = str(i*5);
index = (i*5 < 99) ? "0" + index : index;
index = (i*5 < 9) ? "0" + index : index;
images_ar[i] = loadImage("PD1" + index + ".JPG");
}
for (int i = 0; i < images_ar.length; i++) {
PImage sliceImage = images_ar[i];
PImage tmpImage = new PImage(256, 256);
sliceImage.loadPixels();
tmpImage.loadPixels();
for (int j = 0; j < sliceImage.pixels.length; j++) {
int pix = sliceImage.pixels[j];
if (brightness(pix) > 1) {
tmpImage.pixels[j] = pix;
}
else {
tmpImage.pixels[j] = color(0, 0, 0, 0);
}
}
sliceImage.updatePixels();
masks_ar[i] = tmpImage;
}
}
void draw()
{
background(15, 5, 5);
float hw = images_ar[0].width / 2 / 100;
float hh = images_ar[0].height / 2 / 100;
float stepY = 0.045;
float z;
rotateX(-PI/2);
//fill(255, 20);
translate(0, 0, -1);
for (int i = 0; i < bodyDef; i++) {
PImage img = images_ar[i];
img.mask(masks_ar[i]);
textureMode(NORMALIZED);
beginShape(QUADS);
texture(img);
z = i * stepY;
vertex(-hw, -hh, +z, 0, 1);
vertex(+hw, -hh, +z, 1, 1);
vertex(+hw, +hh, +z, 1, 0);
vertex(-hw, +hh, +z, 0, 0);
endShape();
}
}
Thanx, geek fellows.
MrBlaise.