Transparent blitting

Started by ErDetEnAnd?, December 22, 2008, 04:18:33 PM

Previous topic - Next topic

ErDetEnAnd?

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?

EgonOlsen

Quote from: ErDetEnAnd? on December 22, 2008, 04:18:33 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


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.

ErDetEnAnd?

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?

ErDetEnAnd?

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?

EgonOlsen

#4
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.

ErDetEnAnd?

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?

ErDetEnAnd?

Using the jar you just posting is not scaling the bill boards, when scaling its parent.

EgonOlsen

Quote from: ErDetEnAnd? on December 22, 2008, 08:28:01 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.

EgonOlsen

Quote from: ErDetEnAnd? on December 22, 2008, 08:35:57 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... ???

EgonOlsen

#9
Quote from: ErDetEnAnd? on December 22, 2008, 08:35:57 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... ;)

EgonOlsen


ErDetEnAnd?

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.

EgonOlsen

#12
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.

ErDetEnAnd?

#13
I've just updated the jar with the beta posted above, but with no effect.

// 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.

ErDetEnAnd?

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.