Author Topic: _DONTBLEND wiki statement  (Read 3134 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
_DONTBLEND wiki statement
« on: December 16, 2019, 02:41:02 pm »
The command in question: https://www.qb64.org/wiki/DONTBLEND

And the statement in question: Use CLS or _DONTBLEND to make a new surface background _ALPHA 255 or opaque.

And my enquiry:  How do we use _DONTBLEND  to make a new surface background _ALPHA 255??

From my experience, _DONTBLEND doesn't change alpha levels at all.  All it does is let us set a color to exactly what we specify it to be, without blending it into the existing background.

A little test code to showcase the difference in _DONTBLEND and CLS, in regards to opaque backgrounds:

Code: QB64: [Select]

DONTBLEND never changed the background alpha levels, whereas CLS does.  Is this a case where the wiki is giving us a wrong bit of information, or am I using the command wrong, or just interpreting something wrong?  Exactly how does it "make a new surface background _ALPHA 255 or opaque"?
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: _DONTBLEND wiki statement
« Reply #1 on: December 16, 2019, 02:45:45 pm »
Question 2: WTH is up with the sample code provided?

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1280, 720, 32)
  2. 'CLS
  3. _DONTBLEND '<<< comment out to see the difference
  4.  
  5. LINE (100, 100)-(500, 500), _RGB32(255, 255, 0), BF
  6.  
  7. b& = SaveBackground&
  8.  
  9. PRINT "This is just test junk"
  10. PRINT "Hit any key and the text should disappear, leaving us our pretty yellow box."
  11. RestoreBackground b&
  12.  
  13.  
  14. FUNCTION SaveBackground&
  15. SaveBackground& = _COPYIMAGE(0)
  16.  
  17. SUB RestoreBackground (Image AS LONG)
  18. _PUTIMAGE (200, 200), Image, 0

Exactly what the heck is this supposed to be doing? 

"Hit any key and the text should disappear, leaving us our pretty yellow box."...

...Except the text doesn't go anywhere..

I'm completely lost by this wiki entry! 

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: _DONTBLEND wiki statement
« Reply #2 on: December 16, 2019, 03:03:06 pm »
I think this is what the wiki code is trying to demonstrate:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1280, 720, 32)
  2. 'CLS
  3. _DONTBLEND '<<< comment out to see the difference
  4.  
  5. LINE (100, 100)-(500, 500), _RGB32(255, 255, 0), BF
  6.  
  7. b& = SaveBackground&
  8.  
  9.  
  10.  
  11.  
  12. PRINT "This is just test junk"
  13. PRINT "Hit any key and the text should disappear, leaving us our pretty yellow box."
  14. RestoreBackground b&
  15.  
  16.  
  17. FUNCTION SaveBackground&
  18.     SaveBackground& = _COPYIMAGE(0)
  19.  
  20. SUB RestoreBackground (Image AS LONG)
  21.     _PUTIMAGE , Image, 0

At first glance, it appears as if the demo is doing as the original premise states -- it's making the new image opaque, but it's not true.  A quick little change can highlight this fact, indisputably:

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1280, 720, 32)
  2. 'CLS
  3. _DONTBLEND '<<< comment out to see the difference
  4.  
  5. LINE (100, 100)-(500, 500), _RGB32(255, 255, 0), BF
  6.  
  7. b& = SaveBackground&
  8.  
  9.  
  10.  
  11.  
  12. PRINT "This is just test junk"
  13. PRINT "Hit any key and the text should disappear, leaving us our pretty yellow box."
  14. RestoreBackground b&
  15.  
  16.  
  17. FUNCTION SaveBackground&
  18.     SaveBackground& = _COPYIMAGE(0)
  19.  
  20. SUB RestoreBackground (Image AS LONG)
  21.     _PUTIMAGE , Image, 0

Notice where I have it print the hex value of point (0,0)?  It's NOT FF000000; instead, it's just 0.  No red, no blue, no green, no alpha...  It's still completely transparent!



So why are we seeing the difference in results that we're getting??

Because we have _DONTBLEND set and that pure transparent color is simply overwriting the white of the text.  With blend on, we blend transparent and white, get white, and the text remains...

_DONTBLEND didn't make the new screen opaque, or set it to have 255 alpha.  It simply changed our main screen so we didn't blend the transparent color out with the existing color...

Here's a perfect example to prove that: 
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(1280, 720, 32)
  2. 'CLS
  3. _DONTBLEND '<<< comment out to see the difference
  4.  
  5. LINE (100, 100)-(500, 500), _RGB32(255, 255, 0), BF
  6.  
  7. b& = SaveBackground&
  8.  
  9.  
  10. PRINT "This is just test junk"
  11. PRINT "Hit any key and the text should disappear, leaving us our pretty yellow box."
  12.  
  13. _BLEND b& 'set the copied image attribute to blend
  14. _BLEND 0 'set the current page attribute to blend
  15. RestoreBackground b&
  16.  
  17.  
  18. FUNCTION SaveBackground&
  19.     SaveBackground& = _COPYIMAGE(0)
  20.  
  21. SUB RestoreBackground (Image AS LONG)
  22.     _PUTIMAGE , Image, 0

If _dontblend had actually changed the background to having 255 alpha, we couldn't just turn blending back on and have it perform with 0 alpha levels as we're seeing.

Unless someone knows something about this command that I don't, I'm inclined to say the wiki is completely off here with what it's documenting for us. 

Or am I just missing something obvious here?

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: _DONTBLEND wiki statement
« Reply #3 on: December 16, 2019, 03:21:19 pm »
Here's what I'd suggest changing in the entry:

  • If imageHandle& is not valid, an Invalid handle error will occur.
  • _DONTBLEND is faster than the default _BLEND. You may want to disable it, unless you really need to use it in 32 bit.
  • 32 bit screen surface backgrounds (black) have zero _ALPHA so that they are transparent when placed over other surfaces.
  • Use CLS or _DONTBLEND to make a new surface background _ALPHA 255 or opaque.
  • Both _SOURCE and _DEST must have _BLEND enabled, or else colors will NOT blend.


And the examples would probably need to be rewritten so they reflect the actual behavior of the command for us.  ;)


https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: _DONTBLEND wiki statement
« Reply #4 on: December 16, 2019, 03:28:27 pm »
Are you editing it?