Author Topic: Transparent blitting  (Read 7769 times)

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Transparent blitting
« on: December 22, 2008, 04:18:33 pm »
Hello!

How do I blit a dark picture (r/g/b<0x0F) using transparency?

When blitting images the image must fit into a texture, even though the extra space in unwanted. The image cannot be scaled, thus the extra space is made transparent using an alpha channel (see image).



Using a dark(er) image as destination, and a transparent border as source to fit into a texture, blitting by

public void blit(Texture src,
                 int srcX,
                 int srcY,
                 int destX,
                 int destY,
                 int width,
                 int height,
                 boolean transparent)

doesn't make use of the alpha values. So how do I fit a darker image into a texture, showing only the image?
« Last Edit: December 22, 2008, 04:21:26 pm by ErDetEnAnd? »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Transparent blitting
« Reply #1 on: December 22, 2008, 05:37:41 pm »
How do I blit a dark picture (r/g/b<0x0F) using transparency?
When using the hardware renderer, the alpha channel will always work. When using the software renderer, the

Code: [Select]
public void blit(Texture src, int srcX, int srcY, int destX, int destY, int sourceWidth, int sourceHeight, int destWidth, int destHeight, int transValue, boolean additive, Color addColor)
-method should do the trick. Internally, it wraps the blitting call into an Overlay (which i consider to be a bit hacky... ;D), so you may also use an Overlay directly, if that is more appropriate in your case.

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Transparent blitting
« Reply #2 on: December 22, 2008, 06:35:55 pm »
Thank you.

I had to update my jPCT version in order to get that method, but know my billboarding objects not facing the camera and not transformed. What is changed?

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Transparent blitting
« Reply #3 on: December 22, 2008, 07:59:51 pm »
Another 2 issues:

Where do I find the package version of a downloaded jPCT?

The blit method you refered to makes colors less than 0x0f transparent using transparency. I guess this is correct. However setting the transvalue argument to -1 (disabled), the method is ignoring the alpha-channel. Again, how to I draw a dark image with the only transparent pixels having an alpha-value?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Transparent blitting
« Reply #4 on: December 22, 2008, 08:09:11 pm »
That version has regression bug with bill boarding...try the jar from http://www.jpct.net/download/beta/jpct.jar. It should fix the bill boarding problem again (http://www.jpct.net/forum2/index.php/topic,1253.0.html). The auto-transparency thing with color values below 0x0f only applies to textures that weren't created with an alpha channel. If you create them with one of the appropriate useAlpha-constructors in Texture, the alpha channel will be taken instead.
However, of course alpha is limited to transparency...you may try to use a very high value for the transparency. That should make the dark areas almost opaque while the alpha channel is still taken into account for the transparent parts.
« Last Edit: December 22, 2008, 08:13:41 pm by EgonOlsen »

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Transparent blitting
« Reply #5 on: December 22, 2008, 08:28:01 pm »
Exactly and impressive!

Respect for your work with this engine, but you really should elaborate the rather bland doc for this engine (eg. with references from the blit to the alpha-channel texture). It would take time but really pay off.

Btw. where do I find the version of my jPCT?

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Transparent blitting
« Reply #6 on: December 22, 2008, 08:35:57 pm »
Using the jar you just posting is not scaling the bill boards, when scaling its parent.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Transparent blitting
« Reply #7 on: December 22, 2008, 08:38:45 pm »
Btw. where do I find the version of my jPCT?
Config has a getVersion()-method, but that doesn't reflect sub-versions, so the official release and the jar from the beta-directory will return you the same version number.
Concerning the docs, i agree that they could be better regarding that blitting method and the alpha stuff. I must have forgotten to update them properly because i kinda kludged in both of them in very short time.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Transparent blitting
« Reply #8 on: December 22, 2008, 08:40:17 pm »
Using the jar you just posting is not scaling the bill boards, when scaling its parent.
Did the old one do this? It's actually a merge of the new sources with the ones that contained the fix. I can't see a reason why it should have behaved different before... ???

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Transparent blitting
« Reply #9 on: December 22, 2008, 09:03:22 pm »
Using the jar you just posting is not scaling the bill boards, when scaling its parent.
I can't verify this, albeit i have to admit that the behaviour that i'm getting is wrong too. What i get is, that the scaling of the parent is applied two times to the child, which is wrong. I'll try to fix this...

Edit: I've updated the jar in the beta-directory. The scaling of the parent should now be applied to the child correctly...i should have defined bill boarding as not being support for parent-child-relations much earlier... ;)
« Last Edit: December 22, 2008, 09:10:02 pm by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Transparent blitting
« Reply #10 on: December 23, 2008, 01:08:02 pm »
Did it work  ???

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Transparent blitting
« Reply #11 on: December 23, 2008, 03:33:42 pm »
I'm affraid not. I'm using the billboards for text which I want to keep with a certain size regardless of parent scaling. This is (was) achived by scale inverted on the billboards. Now I cant scale the billboards seperately. The jPCT version I used before was about 1 year old.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Transparent blitting
« Reply #12 on: December 23, 2008, 08:23:29 pm »
So the parent has 0.5f (for example) and the child gets a 2f to compensate for that and to get a child-scaling of actually 1f? If so, then that works fine in my test case. I can't verify your problem. Either the version you were using was working wrong (earlier versions didn't take the parent's scaling into account, which was actually wrong behavior) or you are doing something different. Can you provide a simple test case that shows the problem?

Edit: And make sure that you really have the latest jar-version. I've updated it twice yesterday. If you've got an in-between-version, you may got a buggy one.
« Last Edit: December 23, 2008, 08:30:24 pm by EgonOlsen »

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Transparent blitting
« Reply #13 on: December 25, 2008, 11:49:59 am »
I've just updated the jar with the beta posted above, but with no effect.

Code: [Select]
// Scale on parent
mc.getOriginRoom().setScale(scale);

// Scale inverted on billboards (which are children)
for (RoomObject3D ro3d: mc.getRooms()) {
    ro3d.getBillBoardObject3D().setScale(bbscale);

You got my scaling right. Whatever I scale the parent, its children* is scaled with its reciprocal value (which worked fine before). This should leave the size of the billboards unchanged for the viewer.

Here are some numbers i use. scale is used on parent while bbscale on the billboards. What I get are bigger billboards (even on first setScale (for keeping the culumative out of the picture)).

scale=1.05, bbscale=0.952381, diff=1.0
scale=1.1024998, bbscale=0.90702957, diff=0.99999994
scale=1.1576248, bbscale=0.8638377, diff=1.0
scale=1.2155061, bbscale=0.82270265, diff=1.0000001
scale=1.2762814, bbscale=0.78352636, diff=1.0000001
scale=1.3400954, bbscale=0.74621564, diff=1.0000001
scale=1.4071001, bbscale=0.7106816, diff=1.0000001

*) Its childrens children actually.
« Last Edit: December 25, 2008, 11:56:45 am by ErDetEnAnd? »

Offline ErDetEnAnd?

  • int
  • **
  • Posts: 87
    • View Profile
Re: Transparent blitting
« Reply #14 on: December 25, 2008, 12:06:46 pm »
Found a solution!

If the billboard is not a successor of the object you scale, but eg. a child to the successor, the billboard scaling is not affected. To do what I want, the billboard must be a successor to the scaled.