SyntaxBomb - Indie Coders

Languages & Coding => BlitzMax / BlitzMax NG => Topic started by: takis76 on September 22, 2020, 22:34:03

Title: I have a new question about color replacing
Post by: takis76 on September 22, 2020, 22:34:03
Hello, my friends,
I have one question and I do not know if this is possible.

I have some images that I use them as mask images to clear my light effects. (You have seen one light effect example for my game).
I have a question. I have one image which has only 2 colors one foreground color with RGB(255,255,255) and the background color RGB(255,000,255) to be used as transparent.

I have one Mask example uploaded to see how my image masks look like.
Is it possible to fill a color over this image (Imagine like flooding a color on the image using a paint program using the paint tool) but to do this on runtime?
For example, is it possible to select a position inside this image and flood fill it with a specific color or just replace a specific color with another one.
The mask I have uploaded has Pink color (255,000,255) as transparent and (255,255,255) as solid. If it is possible just to choose which color wants to be replaced with another one without change the image and this image will be reused at once.

The second gray one is the example of how the image will become after replacing the white color RGB(255,255,255) with gray RGB(128,128,128).

For now, I am using multiple images (Pre-painted) for different colors to do my effect. But if I will have many different mask shapes I will need to have pre-painted images for all of these masks.  (Darker image mask, makes a darker light replacement). With these masks, I am erasing the lights.
Title: Re: I have a new question about color replacing
Post by: Matty on September 22, 2020, 23:47:26
Yes, it can be done however I don't know the exact syntax of the language you are using.

An easy way if you want to replace just one colour is set the mask to being that colour then draw the image on top of an image with the replacement colour,  then set the mask back to the original colour.
Title: Re: I have a new question about color replacing
Post by: takis76 on September 23, 2020, 00:09:02
What you mean saying what systax of the language I am using? (I am using the Blitzmax).

These masks are just light masks.

I use something like this:
Code: [Select]
DrawImage(Wall_Lightmask_Images[Int(Wall_Lightmask_string)], 048, 016)

The Wall_Lightmask_string is something like this "10104" and I am casting it to an integer value.

If I have placed an image using the SetBlend(LIGHTBLEND) make the area Brighter with the image I have placed.
Using the SetBlend(MASKBLEND) make the area Darker with the mask image I have used.
Using a darker color mask I am clearing the area of the pixels using the specific darker mask. Changing the color of these image masks on runtime making the color darker. I am simulating the darkness around. I have 9 levels of light volume. The 9 is the total bright and the 1 is the darkest.
So if I will use a prepainted masked image I am cleaning the area of the pixels with the specific color of the mask.

For example, if the pixels around have lit with LIGHTBLEND color RGB(128,128,128) and If will place a light with brighter values that RGB(128,128,128) I will need to place a mask with color RGB(128,128,128) to clean the brighter area of this light with the same value because the darkness around is RGB(128,128,128) too.

The mask in the example presents a portcullis door and if there is a light behind, the visible area of the door erases the light behind this mask with the same value of the dark pixels around which are RGB(128,128,128) too. I am solving my problem using many different prepainted images with all 9 bright levels. But using 23 Masks X 9 bright values I need to have 23x9=207 images of portcullis shadows. I will need to have thousands of images for each object that needs to cover the light in the background. But changing the color on run time I will have only the current mask, in my example, I will have only 23 mask images instead of 207. I will have 9 times fewer images.
Title: Re: I have a new question about color replacing
Post by: Derron on September 23, 2020, 06:40:51
If you have white as the pixel color drawn (and pink as the mask color)

- you could make pink transparent (alpha channel) and use AlphaBlend as mode
- setcolor (tint r, tint g, tint b) and then draw your image
- setalpha can also modify the impact

Afterwards restore old setcolor and setalpha (backup before with getcolor annd getalpha)

Title: Re: I have a new question about color replacing
Post by: takis76 on September 23, 2020, 23:29:36
Maybe I managed to fix my problem.
Your advice partially worked.
I changed all my mask graphics to a transparent channel without Pink color RGB(255,000,255). -> This worked.

The SetBlend(ALPHABLEND) option didn't make any difference I used the SetBlend(MASKBLEND) to clean my lights.
But the problem which caused my mask to be bright and forcing me to use prepainted darker masks was the underwater shader which I was called it
in the game loop many times and caused my light masks to become bright. (Unknown error for me and I don't know why the shader causes all images that used LIGHTBLEND option to see them bright even I change their color or set their transparency or even placing darker masks over them they still presented bright). Removing some multiple shader calls fixed the bright sprites (I realized the bright masks appeared when I had the shader activated).
Also, many weird things were happened when I used the drawrect() command. I removed lot of code and I did lots of changes and it seems it is working for now. But I will do more tests and I will finish the whole routine. Not all walls replaced yet. But it seems this will work.
Title: Re: I have a new question about color replacing
Post by: Derron on September 24, 2020, 06:21:53
Alpha channel means there is a rgb color on transparent pixels...but set 0-100% transparent.
Dunno if maskblend works fine with it.

SimplePortal 2.3.6 © 2008-2014, SimplePortal