bmap_to_alpha does not work after pixel_to_bmap.

Posted By: Henning

bmap_to_alpha does not work after pixel_to_bmap. - 02/19/10 15:18

Hello,

I tried to make a multitexture terrain by reading a color coded feature map, convert each feature area to an alpha map and apply this with the proper texture on the terrain. I.e. where the feature map has blue color, water texture will show.

But after painting white color pixels onto a map, it cannot be converted to an alpha map with bmap_to_alpha. It works, when you do not paint on that map before. I tried several workarounds, store and reload the map, bmap_blit it to another name, etc.
The only working solution is to create a new one with bmap_create, but then - surprise - it is upside down.

So, I think I found two problems. No reports anywhere in the forum.

Version: Commercial 7.82
Here some code (inputPic should be black at 1,1, elsewhere some color):

#include <acknex.h>
#include <default.c>

BMAP* inPic = "inputPic.tga"; // 32x32 pixel, 24 bit tga, no alpha
//BMAP* wAlpha = "lila.tga";
BMAP* wAlpha;
var format;
var wPix;

function main () {
wait (1);

format = bmap_lock (inPic,0);
wPix = pixel_for_vec (vector (255,255,255),100,format);
pixel_to_bmap (inPic,1,1,wPix);
bmap_unlock (inPic);
bmap_save (inPic, "output1.tga");

wait (-1); // give some time for saving

wAlpha = bmap_create ("output1.tga");
// bmap_blit (wAlpha,inPic,NULL,NULL);

bmap_to_alpha (wAlpha, 100); // now 32 bit with alpha
bmap_save (wAlpha, "output2.tga");

sys_exit (NULL);
}

I would be pleased to get a simpler solution.
Posted By: jcl

Re: bmap_to_alpha does not work after pixel_to_bmap. - 02/24/10 10:47

Yes, this is quite possible - I'm pretty sure bmap_to_alpha uses the original bitmap data, not the written pixels. I'll check and if this is the case, I'll mention this more clear in the manual.

- bmap_to_alpha was a legacy function from A4 times when alpha channel textures weren't supported yet. You won't need it in A7 - just use 32 bit TGA already, and write 32 bit pixels.
Posted By: Henning

Re: bmap_to_alpha does not work after pixel_to_bmap. - 02/25/10 08:33

Hello Jcl,

thank you for the quick response, but using prepared alpha maps does not solve my problem, because I want to generate the ground textures at run-time. I have a 24x24km area and a feature map showing yellow for main roads, grey for secondary roads, blue for water, two shades of green for wood and so on. From this I want to calculate 8 different alpha maps for the multi-texture terrain. But besides that I am a little afraid that it might have too much impact on FPS. So, as a workaround I prepared normal tex maps by hand, but that does not look so good.

Best regards
Henning

By the way, A7 is a great tool, exactly what I looked for since 25 years, when I started with VRML.
Posted By: jcl

Re: bmap_to_alpha does not work after pixel_to_bmap. - 02/26/10 10:04

You can either convert your image to 32 bit alpha first and write into it afterwards.

Or create a new 32-bit BMAP with bmap_create(...), and use it as write target. That would be the normal way to manipulate a source image and save it under a different name.
Posted By: Henning

Re: bmap_to_alpha does not work after pixel_to_bmap. - 03/24/10 09:05

Originally Posted By: jcl
Or create a new 32-bit BMAP with bmap_create(...), and use it as write target. That would be the normal way to manipulate a source image and save it under a different name.


Perfectly, that works. Thanks.
© 2024 lite-C Forums