Author Topic: Need some help with texture tranparency  (Read 3154 times)

Offline Miridian

  • byte
  • *
  • Posts: 15
    • View Profile
    • My Blog :)
Need some help with texture tranparency
« on: January 15, 2011, 11:26:50 pm »
Hi,

I would like to show some text above some 3d Objects.
Searching and trying different sollutions the whole day I capitulate now and ask here.
I cannot find a solution how to make the black background of the texture transparent.
Sample code:
Code: [Select]


Paint paint = new Paint();
paint.setColor(Color.rgb(0, 50, 0));
Bitmap.Config config = Bitmap.Config.ARGB_8888;
FontMetricsInt fontMetrics = paint.getFontMetricsInt();
int baseline = -fontMetrics.top;
Bitmap charImage = Bitmap.createBitmap(128, 128, config);
Canvas canvas = new Canvas(charImage);
canvas.drawRGB(0,0,0);
canvas.drawText("here will be some text", 1, baseline, paint);
Texture texture = new Texture(charImage,false);
TextureManager.getInstance().addTexture("texture", texture);
plane = Primitives.getPlane(10, 6);
plane.setLighting(Object3D.LIGHTING_NO_LIGHTS);
RGBColor c=new RGBColor(255,255,255);
plane.setAdditionalColor(c);
plane.setTexture("texture");
plane.setTransparency(200);
plane.setTransparencyMode(Object3D.TRANSPARENCY_MODE_ADD);
plane.strip();
plane.build();

world.addObject(plane);

With this code the background is not visible but my text is too bright and it is transparent too :D
Please help me. Sorry I am sure it is very simple but I just dont get on it.

Offline Miridian

  • byte
  • *
  • Posts: 15
    • View Profile
    • My Blog :)
Re: Need some help with texture tranparency
« Reply #1 on: January 19, 2011, 10:27:00 pm »
Still not losing the hope someone will be so friendly and help me ...  ::)
I uploaded a small example project. (It was the HelloWorld-AE before. I just added a texture and a plane)
https://spideroak.com/browse/share/Miridian/Public

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Need some help with texture tranparency
« Reply #2 on: January 19, 2011, 11:05:46 pm »
Sorry, i somehow forgot to answer this one...i tried your test project but i somehow fail to see the issue. Just remove the call to setTransparencyMode() and you'll get default transparency (not additive, which is obviously not what you want). jPCT takes care of making the black areas transparent by default. If you want more control, you can use

Code: [Select]
paint.setColor(Color.argb(255, 0, 50, 0));
...
canvas.drawARGB(0, 0, 0, 0);
...
Texture texture = new Texture(charImage, true);

instead, but in this case the outcome will be the same. But maybe i haven't fully understood the problem here. A commented screen shot might help in that case.

Offline Miridian

  • byte
  • *
  • Posts: 15
    • View Profile
    • My Blog :)
Re: Need some help with texture tranparency
« Reply #3 on: January 20, 2011, 11:31:27 am »
Thanks it works now.
I think i forgot to try a higher value than 1 of Transparency before i added the TransparencyMode.

I have a question about the text.
How can I draw it in the middle of the plane?
I already tried paint.setTextAlign(Paint.Align.CENTER) but it doesnt work... The text is more left than before.
Is there a simple method to do it or do i have to claculate it ?  :-\

Sorry for my horrible english.