Page 1 of 1

Setting texture alpha

Posted: Tue Jul 20, 2010 1:44 pm
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.

Posted: Tue Jul 20, 2010 2:21 pm
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... ;)

Posted: Tue Jul 20, 2010 2:34 pm
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.

Posted: Tue Jul 20, 2010 2:39 pm
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... ;)

Posted: Tue Jul 20, 2010 6:56 pm
by bonsalty
what exactly is lock supposed to do? what if I dont lock the texture and manipulate it?

Posted: Tue Jul 20, 2010 7:37 pm
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.

Posted: Thu Jul 22, 2010 8:26 pm
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?

Posted: Thu Jul 22, 2010 8:29 pm
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?

Posted: Thu Jul 22, 2010 9:50 pm
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.

Posted: Fri Jul 23, 2010 5:29 pm
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.

Posted: Fri Jul 23, 2010 5:31 pm
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.

Posted: Fri Jul 23, 2010 6:40 pm
by DtD
If you are creating your own textures then it should be even easier to make it a PNG from the start =P