Author Topic: changing alpha when blitting a texture  (Read 13207 times)

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: changing alpha when blitting a texture
« Reply #15 on: March 17, 2008, 08:39:22 pm »
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 ?

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: changing alpha when blitting a texture
« Reply #16 on: March 17, 2008, 09:26:01 pm »
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
« Last Edit: March 17, 2008, 09:31:42 pm by raft »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: changing alpha when blitting a texture
« Reply #17 on: March 17, 2008, 11:52:20 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.

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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: changing alpha when blitting a texture
« Reply #18 on: March 17, 2008, 11:55:46 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.
« Last Edit: March 18, 2008, 12:00:57 am by EgonOlsen »

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: changing alpha when blitting a texture
« Reply #19 on: March 18, 2008, 10:37:12 am »
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 ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: changing alpha when blitting a texture
« Reply #20 on: March 18, 2008, 10:43:21 am »
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.

Offline raft

  • quad
  • ******
  • Posts: 1993
    • View Profile
    • http://www.aptalkarga.com
Re: changing alpha when blitting a texture
« Reply #21 on: March 18, 2008, 10:51:09 am »
yes, it did help, it also helped letters, both methods blit the same now :) thank you ;D

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: changing alpha when blitting a texture
« Reply #22 on: March 18, 2008, 10:57:36 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...).