changing alpha when blitting a texture

Started by raft, March 15, 2008, 01:41:38 AM

Previous topic - Next topic

raft

no CRC error this time ;)

thank you ;) i guess the transparency argument works as it's for Object3D.setTransparency(int) and for GL renderer uses Config.glTransparencyMul and Config.glTransparencyOffset, right ?

it seemed to work ok, except i cannot blit a texture with no transparency but using alpha information: i give -1 as trans value and except transparent parts of my texture remains transparent, as the previous blit method does. but it blits transparent parts as black. i created the texture to use alpha

btw, what is the exact meaning of texture constructor paramater useAlpha ? if i create a texture with no alpha and transparent blit with old method, it correctly blits transparently. where does that alpha info comes from ?

raft

#16
a few more minor things:

* 0 is the highest transparency as it's in Object3D right ? docs say the opposite ;)
* old blit method creates much sharper edges, but i guess that's because of that transparency thing, i had to give a transparency to make transparent parts of my texture invisible

EgonOlsen

Quote from: raft on March 17, 2008, 08:39:22 PM
i guess the transparency argument works as it's for Object3D.setTransparency(int) and for GL renderer uses Config.glTransparencyMul and Config.glTransparencyOffset, right ?
Yes, i uses the same formula.

Quote from: raft on March 17, 2008, 08:39:22 PM
it seemed to work ok, except i cannot blit a texture with no transparency but using alpha information: i give -1 as trans value and except transparent parts of my texture remains transparent, as the previous blit method does. but it blits transparent parts as black. i created the texture to use alpha
You can set a high value for transparency which basically is opaque for everything with an alpha of 255. If you load a texture, jPCT automatically sets all black (or almost black) parts to alpha 0, all the others to alpha 255. To disable this behaviour, you've to create the texture with alpha (that's what the constructor is for). The alpha channel is part of the texture. PNG for example is a suitable format, because it supports an alpha channel.
If you don't have an alpha channel in your texture, you can add your own by using an ITextureEffect.

EgonOlsen

#18
Quote from: raft on March 17, 2008, 09:26:01 PM
* 0 is the highest transparency as it's in Object3D right ? docs say the opposite ;)
* old blit method creates much sharper edges, but i guess that's because of that transparency thing, i had to give a transparency to make transparent parts of my texture invisible
* I'll correct this. I meant that 0 is lowest value for anything none opaque, which is true but pointless information... ;D
* Edges should be sharp as long as you don't scale. If you do, normal bilinear filtering applies. It's a normal textured polygon afterall. If you want sharp (but blocky) edges, do a setGLFiltering(false) on the texture.

raft

thanks for the explanations :)

i'm a bit confused about transparency. here is a shot:


for both text and bubbles, upper lines are blitted by old method and lower lines are with new one. source texture is same for both lines. for bubbles transparency increases from left to right: -200, 0, 200, 400.. for text similar, -100, 0, 100, 200..

text transparency is alright, it cannot be seen in the shot but lower line of letters are completely opaque starting from 'c' as expected. the right most bubble has a transparency value of 800 but it's still transparent ?

i guess, the term 'sharp' was incorrect but you may see lower line of text is jagged. those letters are rendered to texture by using antialiasing. i thought antialiasing wont help much and even will look worse in this case, as we dont know the background color when we are creating the texture, but surprisingly it works quite fine for upper line. it may be because they're rendered to a transparent background (BufferedImage.TYPE_INT_ARGB) but not sure ?

EgonOlsen

Maybe rendering with antialiasing creates alpha information...i'm not sure about this, but it looks like it. It would make sense anyway to do this, so maybe SUN got this right.

About the bubbles: You are obviously using additive blending. Try to set this parameter to false to see if it helps. Additive blending will never be opaque unless you add white, which is what you do for the letters.

raft

yes, it did help, it also helped letters, both methods blit the same now :) thank you ;D

EgonOlsen

Quote from: raft on March 18, 2008, 10:51:09 AM
yes, it did help, it also helped letters
Yes, because doing a additive blending with high transparency value makes almost everything white. It's adding the color multiple times until it's all white (or red or green or blue...).