Setting texture alpha

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
bonsalty
Posts: 120
Joined: Thu Dec 10, 2009 1:30 pm
Location: Budapest,Hungary

Setting texture alpha

Post by bonsalty »

Suppose I load a jpg texture, which has obviously no alha channel, can I set the global alpha channel somehow? MakeKeyColortexture just changes one color to the desired alpha.
Tomi
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

yes, as soon as the texture is in memory it's stored in ARGB format...
so you can lock the texture, change the alpha values and unlock the texture again... ;)
it's also possible with just using setPixel(...) but slower... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

You could also change the alpha value of the vertex colors of the mesh you're rendering the texture on for a similar effect. No need to change the texture itself.
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

slavik262 wrote:You could also change the alpha value of the vertex colors of the mesh you're rendering the texture on for a similar effect.
supposed the texture is meant for use with a mesh... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
bonsalty
Posts: 120
Joined: Thu Dec 10, 2009 1:30 pm
Location: Budapest,Hungary

Post by bonsalty »

what exactly is lock supposed to do? what if I dont lock the texture and manipulate it?
Tomi
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

How would you? Lock returns a pointer to the start of the memory block that contains the texture data. It also "locks" the texture in that the rest of the system won't use it while you're modifying it. When you're done you unlock it so the system knows that it can use it again.
bonsalty
Posts: 120
Joined: Thu Dec 10, 2009 1:30 pm
Location: Budapest,Hungary

Post by bonsalty »

Another thing: I was wrong -makeColorKeyTexture makes the actual color completly transparent. Is there any stuff, to make it not fully transparent or should I change each pixel to the desired one by one?
Tomi
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

It sounds like you could really use a texture format that supports alpha channel transparency, like PNG. Is there any reason you want to use JPEGs?
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

I agree with slavik, this would all be much easier if you used a proper format. JPEG lacks transparency and uses a very lossy compression, so it is not well suited for textures.
bonsalty
Posts: 120
Joined: Thu Dec 10, 2009 1:30 pm
Location: Budapest,Hungary

Post by bonsalty »

I create my own textures , not static images, that would be easy. I solved the problem with simply using the GetPixel and PutPixel attribute of IImage, it isnt that slow.
Tomi
slavik262
Posts: 753
Joined: Sun Nov 22, 2009 9:25 pm
Location: Wisconsin, USA

Post by slavik262 »

That works as long as you don't do it in real-time. Individual pixel manipulation is slow on the CPU - that's why shaders were developed.
DtD
Posts: 264
Joined: Mon Aug 11, 2008 7:05 am
Location: Kansas
Contact:

Post by DtD »

If you are creating your own textures then it should be even easier to make it a PNG from the start =P
Post Reply