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 › Alpha texture almost working...
Page Index Toggle Pages: 1
Alpha texture almost working... (Read 713 times)
Alpha texture almost working...
Jul 8th, 2006, 5:17pm
 
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.
Re: Alpha texture almost working...
Reply #1 - Jul 8th, 2006, 6:17pm
 
It's applied on both sides, however you're coming up against the z-order problem with transparency. You have to draw them furthermost to nearmost for alpha to work. Try: hint(DEPTH_SORT); (IIRC)
Re: Alpha texture almost working...
Reply #2 - Jul 8th, 2006, 8:46pm
 
It worked all right!
I figured out there's a lot of threads about this particular issue.
I have no idea what z-near and z-far mean.

Thanx a lot.


MrBL
Page Index Toggle Pages: 1