No warning to mix screen 0 and screen graphic commands!
#1
Help!
For all coders like me that are too old to abandon the old Qbasic Keywords vs new QB63pe keywords, it should be a warning AI in the parser!

run this code and you can experimenting what I'm saying.
Code: (Select All)
Dim Shared S1 As Long, S2 As Long
S1 = _NewImage(1200, 900, 32)
S2 = _NewImage(1200, 300, 32)
_SetAlpha 100, 0, S2
Screen S1
Paint (1, 1), _RGBA32(0, 100, 100, 256)
_Delay 1
_Dest S2
Print "If you see color back to this text all is ok"
_PutImage (1, 600), S2, S1
well, if you watch at the output... you see that all that is a screen 0 output (PRINT in this case)  has been _putimaged on the application screen without no alpha effect!
At a first time it has been clear to my old mind! Why the part of S2 that brings PRINT output is not under the effect of _setalpha? 
Yes PRINT is a keyword of SCREEN 0, but I believe that _setalpha should work on the whole S2 and not only to the part that brings a graphic effect.
In other words I should get this result if I make output directly to the main screen, while if I copy a screen that has a not full grade of trasparency (alpha < 256)  I should get that the whole image shows the trasparency effect.

In this case it seems that copying the output of a SCREEN 0 let it at screen 0 level! 
Like I cannot use screen function with graphic text (using Fonts).
Reply
#2
I'm sure you already tried this:

https://qb64phoenix.com/qb64wiki/index.php/PRINTMODE

But this could be a (Dolores Derriere in fractured French) if you need to erase the letters to write something else over the same field.
Reply
#3
I think you're mixing up the behavior of
_SetAlpha
with
Color
.
_SetAlpha
is a command that changes the Current contents of an image at the time you run the command, it does not change anything about what happens to the image after that point, and each pixel of the image has its own alpha value. Thus doing
_SetAlpha 100, 0, S2
only changes the current black pixels to have 100 alpha, it has no impact on any black pixels created after that point (such as the ones from
Print
) and they are free to have any alpha value they want.

When you
Print
on a 32-bit image, the entire RGBA values used for the foreground and background colors come from the current
Color
setting, so any existing alpha value for those pixels will be overridden by those RGBA colors. If you try the below code that adds a
Color
line, I believe you get the behavior you're looking for:

Code: (Select All)
Dim Shared S1 As Long, S2 As Long
S1 = _NewImage(1200, 900, 32)
S2 = _NewImage(1200, 300, 32)
_SetAlpha 100, 0, S2
Screen S1
Paint (1, 1), _RGBA32(0, 100, 100, 256)
_Delay 1
_Dest S2

Color , _RGBA32(0, 0, 0, 100) ' Make the background color black with 100 alpha

Print "If you see color back to this text all is ok"
_PutImage (1, 600), S2, S1

Alternatively, like mnrvovrfc mentioned using _PrintMode is generally an easier way to do this, it allows you to just simply turn off the background color of
Print
all together. If you do that then your usage of
_SetAlpha
will work like you were expecting because
Print
just won't touch the existing black pixels that already have 100 alpha due to
_SetAlpha
.
Reply
#4
(06-14-2023, 02:37 AM)mnrvovrfc Wrote: I'm sure you already tried this:

https://qb64phoenix.com/qb64wiki/index.php/PRINTMODE

But this could be a (Dolores Derriere in fractured French) if you need to erase the letters to write something else over the same field.
Thnks for you feedback but
PRINTMODE is a good guy but as you can see let you have a text background or a text foreground totally transparent. No a fadeness and no both background and foreground togheter transparent /fading. So its goals are not the same that I'm searching.

Moreover there is the issue that you said in french language.
Reply
#5
@DSman
hi thanks for replying

1. _setalpha works on actual image and not to the future changement of it
If this is true I can try to set alpha channel the instant before using _putimage and ths must garantee me to get a half transparent image copied. But this code demonstrates that it is not so.
Code: (Select All)
Dim Shared S1 As Long, S2 As Long ' declaring pointer variables
S1 = _NewImage(1200, 900, 32) ' first image linked to pointer
S2 = _NewImage(1200, 300, 32) ' second image linked to pointer
'_SetAlpha 100, 0, S2  '<--- setting the second image grade of transparency (more than half transparent)
Screen S1 ' it creates screen of application
Paint (1, 1), _RGBA32(0, 50, 100, 256) ' we colour alla screen   with dark blue
_Delay 1 ' it waits a second
_Dest S2 'we direct output to image S2
Print "If you see color back to this text all is ok" ' print on S2 as screen text mode = Screen 0 legacy
_SetAlpha 100, 0, S2 '<--- setting the second image grade of transparency (more than half transparent)
_PutImage (1, 600), S2, S1 'it copies S2 on S1 starting from point X 1 Y 600
No changements if I set before o after PRINT on S2.

[Image: image.png]



Yes PRINT works only with alpha set to 255, indipendently from alpha setting of the image (screen) on which it works.
So you are right I am mixing too much COLOR with _SETALPHA... I must use _RGBA with COLOR to get this fading effect! Text is indipendent from _alpha settings of image!  Run the following code 
Code: (Select All)
Dim Shared S1 As Long, S2 As Long ' declaring pointer variables
S1 = _NewImage(1200, 900, 32) ' first image linked to pointer
S2 = _NewImage(1200, 300, 32) ' second image linked to pointer
'_SetAlpha 100, 0, S2  '<--- setting the second image grade of transparency (more than half transparent)
Screen S1 ' it creates screen of application
Paint (1, 1), _RGBA32(0, 50, 100, 256) ' we colour alla screen   with dark blue
_Delay 1 ' it waits a second
_Dest S2 'we direct output to image S2
Color _RGBA32(255, 255, 255, 100), _RGBA(0, 0, 0, 100)
Print "If you see color back to this text all is ok" ' print on S2 as screen text mode = Screen 0 legacy
_SetAlpha 100, 0, S2 '<--- setting the second image grade of transparency (more than half transparent)
_PutImage (1, 600), S2, S1 'it copies S2 on S1 starting from point X 1 Y 600
and TADA!

[Image: immagine-2023-06-14-143809002.png]
Here Text and its background are fading!

Thanks for your helps, so you suggest me  what to do to go on!
Reply
#6
(06-14-2023, 12:40 PM)TempodiBasic Wrote: If this is true I can try to set alpha channel the instant before using _putimage and ths must garantee me to get a half transparent image copied. But this code demonstrates that it is not so.
No changements if I set before o after PRINT on S2.
Ah, there's one more catch that I missed - the color provided to _SetAlpha also has its own alpha value which must match the existing value. IE. You're using 0 as the color, which is black with an alpha 0. Since none of the black pixels currently have an alpha 0 your _SetAlpha command doesn't end up doing anything. What you really want is this:

Code: (Select All)
_SetAlpha 100, _RGBA32(0, 0, 0, 0) TO _RGBA32(0, 0, 0, 255), S2
That modifies all pixels with a color within that range, which covers all black pixels regardless of the alpha value.
Reply
#7
Hi DSman
yes using the range of black color we get black color set to 100 alpha channel
But
we must do the same work on the foreground color of text ( white color)

so the complete command is
Code: (Select All)
_SetAlpha 100, _RGBA32(0, 0, 0, 0) To _RGBA32(0, 0, 0, 255), S2 '<--- setting the second image grade of transparency (more than half transparent)
_SetAlpha 100, _RGBA32(255, 255, 255, 0) To _RGBA32(255, 255, 255, 255), S2
And from here my doubt starts:
 if _SETALPHA works on all the image why does not do this work when we omit a range of color to say all colors into the picture?
Reply
#8
(06-16-2023, 01:51 PM)TempodiBasic Wrote: if _SETALPHA works on all the image why does not do this work when we omit a range of color to say all colors into the picture?
Well, you never did that Big Grin You were doing
_SetAlpha 100, 0
which is equivalent to
_SetAlpha 100, _RGBA32(0, 0, 0, 0)
, a specific color value. If you want to set the alpha for every pixel regardless of color I believe you can omit the second argument all together and do
_SetAlpha 100
. Or alternatively with an image,
_SetAlpha 100, , S2
.
Reply
#9
(06-16-2023, 03:54 PM)DSMan195276 Wrote:
(06-16-2023, 01:51 PM)TempodiBasic Wrote: if _SETALPHA works on all the image why does not do this work when we omit a range of color to say all colors into the picture?
Well, you never did that Big Grin You were doing
_SetAlpha 100, 0
which is equivalent to
_SetAlpha 100, _RGBA32(0, 0, 0, 0)
, a specific color value. If you want to set the alpha for every pixel regardless of color I believe you can omit the second argument all together and do
_SetAlpha 100
. Or alternatively with an image,
_SetAlpha 100, , S2
.
Right! You are right!
using _setalpha transparency%,  , HandleImage&   OR _setalpha transparency%  we get the same result of fading both for background color both for foreground color.

Thank you for more feedback! It appeared me strange that _setalpha did not work on the whole image... there were 2 obstacles
1. _setalpha must be applied just before _putimage
2. the sintax of _setalpha need a comma to distinguish between color and handleimage.
Reply




Users browsing this thread: 3 Guest(s)