March 05, 2021, 01:37:37 AM

Author Topic: drawBlock in blitzMax ?  (Read 2183 times)

Offline meems

drawBlock in blitzMax ?
« on: February 23, 2018, 03:25:57 PM »
hi, whats the blitzmax equivalent of the blitz command DrawBlock ?

Offline Derron

Re: drawBlock in blitzMax ?
« Reply #1 on: February 23, 2018, 03:30:52 PM »
Such questions should come along with "x does y" description.

if it draws an image:
DrawImage(img, x,y, frame)


bye
Ron

Offline meems

Re: drawBlock in blitzMax ?
« Reply #2 on: February 23, 2018, 03:56:32 PM »
well the difference between drawblock & drawimage is :
 drawblock doesn't have a mask color therefore the background color (black) in an image is drawn. While drawimage will check for black pixels and NOT draw them, preserving what was on the canvas under the black pixels of the image.

Offline Derron

Re: drawBlock in blitzMax ?
« Reply #3 on: February 23, 2018, 04:20:22 PM »
SetMaskColor(...) before doing the LoadImage()
https://en.wikibooks.org/wiki/BlitzMax/Modules/Graphics/Max2D#SetMaskColor

also have a look at the flags when doing your LoadImage()
https://en.wikibooks.org/wiki/BlitzMax/Modules/Graphics/Max2D#LoadImage


bye
Ron

Offline meems

Re: drawBlock in blitzMax ?
« Reply #4 on: February 23, 2018, 06:36:47 PM »
well I had a practice. I discovered I'm asking the wrong side of the question, because the default drawimage in blitzmax is actually the equivalent of drawBlock in blitz
So the answer to the original question is
Code: [Select]
drawimage im,x,y i.e. which draws an image without a mask color.

So the question actually is, what is the blitzmax equivalent of blitz's drawimage? ( an image with a mask color ? )
Despite Derron's links, the answer is not forthcoming, because examples are not given - it seems to be against the laws of blitzmax to actually give code examples. Everything has to be worked out by clue and experiment.

It's likely something to do with the name MASKEDIMAGE.
but attempts such as

im=loadimage ("my_image",MASKEDIMAGE=1)
or
im=loadimage ("my_image",MASKEDIMAGE=-1)
or
im=loadimage ("my_image",flags=MASKEDIMAGE)
or
im=loadimage ("my_image",flags="MASKEDIMAGE")
or
im.MASKEDIMAGE=1

don't work. It's about time after 13 years of BMax that we resolve this mystery and give a code example of how to draw a masked image.

Offline Derron

Re: drawBlock in blitzMax ?
« Reply #5 on: February 23, 2018, 07:17:44 PM »
im=loadimage ("my_image",MASKEDIMAGE=1)

this is interpreted as

im=loadimage ("my_image",TRUE)

as MASKEDIMAGE is a const value of "1" and "1=1" is true...

SetMaskColor(0,0,0) 'mask black
im=loadimage ("my_image",MASKEDIMAGE)
would be right then.


@ Examples
There are surely some samples lurking around - but as the domains were closed google does no longer know about them.

bye
Ron

Offline meems

Re: drawBlock in blitzMax ?
« Reply #6 on: February 23, 2018, 07:46:43 PM »
Code: [Select]
SetMaskColor(0,0,0) 'mask black
im=loadimage ("my_image",MASKEDIMAGE)

tried. Doesn't work.

I found some clue code but it gave strange results.
In all the examples that come with Bmax, there exists one that overlaps images in the program, and therefore requires image mask. Its 'digesteroids' by FlameDuck aka Rob H.
But nowhere in the digesteroids code is any mention of mask image. htf is the image masked?
I copied the digestive image into my mask_test code, and lo and behold, it was masked - this is without any mask code, just like in digesteroids code.
This was odd. Using MSPAint I modified the digestive image slightly, and then reran the mask_test code- the mask had gone, back to drawBlock. I retracted the image modification in MSPaint, and reran the mask_test code -the mask was still gone. Only when I recopied the digestive image did the mask return.
Then I made a 1 pixel change to the digestive image, and saved it. When I did this, MSPaint notified that " Any Transparency will be lost. Continue? "
Aha. png's have their own transparency, and blitzmax uses them it seems. I'll continue to work things out. No wonder the BMax community died off if no-one figured out how to work image masks. It's vital for games.

Offline meems

Re: drawBlock in blitzMax ?
« Reply #7 on: February 23, 2018, 07:51:52 PM »
ok. Its png's that cause the unexpected behaviour. BMax ditches its mask handling when faced with a png. Give Bmax a bitmap and Derron's code works.
so here's the conditional code

Code: [Select]
SetMaskColor(0,0,0) 'mask black
im=loadimage ("my_image.bmp",MASKEDIMAGE) ' must be a bmp, NOT a png
drawimage im,x,y


Offline Derron

Re: drawBlock in blitzMax ?
« Reply #8 on: February 23, 2018, 08:04:51 PM »
What do you want to achieve? Asking as more details help helping.

Just create the PNG with the things of your choice made transparent already.


bye
Ron

Offline meems

Re: drawBlock in blitzMax ?
« Reply #9 on: February 23, 2018, 10:53:18 PM »
nothing special. just good honest standard handling of image draws.

Offline Derron

Re: drawBlock in blitzMax ?
« Reply #10 on: February 24, 2018, 12:32:34 AM »
Ahm...yes.

PNG = with or without alpha channel ("masked")
Tiff = the same

So you expect that SetMaskColor sets the png loading to ignore the alpha mask (set to the innert color - eg. black or white or whatever the creator used until he set the alpha to <255) and set the color you specified to "transparent" ?

If so, then you might tinker with "TPixmap" (LoadPixmap(url) - it loads raw bitmap data).
Another option is to manipulate the loaded data: loop over the pixmap pixels and unset its alpha. Set pixels with maskcolor to transparent instead.

bye
Ron

Offline TomToad

Re: drawBlock in blitzMax ?
« Reply #11 on: February 24, 2018, 08:54:20 AM »
SetBlend SOLIDBLEND
before anything you do not want to have transparency

SetBlend MASKBLEND
before anything in which you want pixels either 100% or completely transparent (must have alpha channel, or be loaded with SetMaskColor() first)

SetBlend ALPHABLEND
Before anything with an alpha channel from 0 through 255 determines the amount of transparency. Equivalent to MASKBLEND if the alpha channel contains only 0 or 255.

SetBlend LIGHTBLEND
Will add the pixels of the image to the pixels of the backbuffer, creating a lighting effect

SetBlend SHADEBLEND
Will multiply the pixels with the backbuffer to cause a shading effect.

Note that SetMaskColor() does not work the way you might think it does.  BlitzMax does not use mask colors while drawing images, it only uses the alpha channel.  SetMaskColor() just tells BlitzMax that while loading any image without an alpha channel, create one and check to see if the pixel color equals the mask color.  If it does, then set the image's alpha for that pixel to 0, otherwise set it to 255.  This happens at load time, so it will not have any affect on images previously loaded.  It also has no affect on images that already have an alpha channel.

So to summarize: The equivalent of DrawBlock is
SetBlend SOLIDBLEND
DrawImage Image,x,y

The equivalent of early blitz DrawImage is
SetBlend ALPHABLEND 'or SetBlend MASKBLEND
DrawImage Image,x,y

Note also that BlitzMax SetMaskColor defaults to 0,0,0.  So if your mask color is black, no need to call SetMaskColor first.  Also SetBlend ALPHABLEND is default, so if you are loading only images that have an alpha channel already, no need to call that.  When you call either of those commands, the state remains the same until you call the command again, so you only need to call them once and not worry about it again until you need to change it.
------------------------------------------------
8 rabbits equals 1 rabbyte.

Offline meems

Re: drawBlock in blitzMax ?
« Reply #12 on: March 07, 2018, 11:32:47 PM »
btw thanks tom. this improved my understanding of blitzmax transparency, i was still having difficulty cos i wasn't aware that mask colors are individually pinned to images at load.

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal