DONTBLEND: Difference between revisions
Jump to navigation
Jump to search
Code by Zom-B
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 22: | Line 22: | ||
''Example 1:'' Use _DONTBLEND when you want the 32 bit screen surface to be opaque so that it covers up other backgrounds. [[CLS]] works too. | ''Example 1:'' Use _DONTBLEND when you want the 32 bit screen surface to be opaque so that it covers up other backgrounds. [[CLS]] works too. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(1280, 720, 32) | {{Cl|SCREEN}} {{Cl|_NEWIMAGE}}({{Text|1280|#F580B1}}, {{Text|720|#F580B1}}, {{Text|32|#F580B1}}) | ||
{{Text|<nowiki>'CLS</nowiki>|#919191}} | |||
{{Cl|_DONTBLEND}} '<<< comment out to see the difference | {{Cl|_DONTBLEND}} {{Text|<nowiki>'<<< comment out to see the difference</nowiki>|#919191}} | ||
{{Cl|LINE}} (100, 100)-(500, 500), {{Cl|_RGB32}}(255, 255, 0), BF | {{Cl|LINE}} ({{Text|100|#F580B1}}, {{Text|100|#F580B1}})-({{Text|500|#F580B1}}, {{Text|500|#F580B1}}), {{Cl|_RGB32}}({{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|0|#F580B1}}), BF | ||
b& = SaveBackground& | b& = {{Text|SaveBackground&|#55FF55}} | ||
{{Cl|PRINT}} "This is just test junk" | {{Cl|PRINT}} {{Text|<nowiki>"This is just test junk"</nowiki>|#FFB100}} | ||
{{Cl|PRINT}} | {{Cl|PRINT}} | ||
{{Cl|PRINT}} "Hit any key and the text should disappear, leaving us our pretty yellow box." | {{Cl|PRINT}} {{Text|<nowiki>"Hit any key and the text should disappear, leaving us our pretty yellow box."</nowiki>|#FFB100}} | ||
{{Cl|SLEEP}} | {{Cl|SLEEP}} | ||
RestoreBackground b& | {{Text|RestoreBackground|#55FF55}} b& | ||
{{Cl|END}} | {{Cl|END}} | ||
{{Cl|FUNCTION}} SaveBackground& | {{Cl|FUNCTION}} {{Text|SaveBackground&|#55FF55}} | ||
SaveBackground& = {{Cl|_COPYIMAGE}}(0) | {{Text|SaveBackground&|#55FF55}} = {{Cl|_COPYIMAGE}}({{Text|0|#F580B1}}) | ||
{{Cl|END FUNCTION}} | {{Cl|END FUNCTION}} | ||
{{Cl|SUB}} RestoreBackground (Image {{Cl|AS}} {{Cl|LONG}}) | {{Cl|SUB}} {{Text|RestoreBackground|#55FF55}} (Image {{Cl|AS}} {{Cl|LONG}}) | ||
{{Cl|_PUTIMAGE}} , Image, 0 | {{Cl|_PUTIMAGE}} , Image, {{Text|0|#F580B1}} | ||
{{Cl|END SUB}} | {{Cl|END SUB}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
---- | |||
''Example 2:'' Turning off blending to create transparency. | ''Example 2:'' Turning off blending to create transparency. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}({{Text|640|#F580B1}}, {{Text|480|#F580B1}}, {{Text|32|#F580B1}}) | |||
alphaSprite& = {{Cl|_NEWIMAGE}}({{Text|64|#F580B1}}, {{Text|64|#F580B1}}, {{Text|32|#F580B1}}) | |||
{{Cl| | {{Cl|_DONTBLEND}} alphaSprite& {{Text|<nowiki>' turn off alpha-blending</nowiki>|#919191}} | ||
alphaSprite& | |||
{{ | {{Text|<nowiki>'Create a simple sprite with transparency</nowiki>|#919191}} | ||
'Create a simple sprite with transparency | |||
{{Cl|_DEST}} alphaSprite& | {{Cl|_DEST}} alphaSprite& | ||
{{Cl|FOR}} y = 0 {{Cl|TO}} 63 | {{Cl|FOR}} y = {{Text|0|#F580B1}} {{Cl|TO}} {{Text|63|#F580B1}} | ||
{{Cl|FOR}} x = {{Text|0|#F580B1}} {{Cl|TO}} {{Text|63|#F580B1}} | |||
alpha = {{Cl|SQR}}((x - {{Text|32|#F580B1}}) ^ {{Text|2|#F580B1}} + (y - {{Text|32|#F580B1}}) ^ {{Text|2|#F580B1}}) / {{Text|32|#F580B1}} | |||
{{Cl|IF}} alpha < {{Text|0|#F580B1}} {{Cl|THEN}} alpha = {{Text|0|#F580B1}} | |||
alpha = ({{Text|1|#F580B1}} - alpha * alpha) {{Text|<nowiki>'parabolic curve</nowiki>|#919191}} | |||
{{Cl|PSET}} (x, y), {{Cl|_RGBA32}}({{Text|255|#F580B1}}, {{Text|255|#F580B1}}, {{Text|255|#F580B1}}, alpha * {{Text|255|#F580B1}}) | |||
{{Cl|NEXT}} | |||
{{Cl|NEXT}} | {{Cl|NEXT}} | ||
'Make a simple background texture | {{Text|<nowiki>'Make a simple background texture</nowiki>|#919191}} | ||
{{Cl|_DEST}} 0 | {{Cl|_DEST}} {{Text|0|#F580B1}} | ||
{{Cl|FOR}} y = 1 {{Cl|TO}} 479 | {{Cl|FOR}} y = {{Text|1|#F580B1}} {{Cl|TO}} {{Text|479|#F580B1}} | ||
{{Cl|FOR}} x = {{Text|0|#F580B1}} {{Cl|TO}} {{Text|639|#F580B1}} | |||
{{Cl|PSET}} (x, y), {{Cl|_RGB32}}(x {{Cl|AND}} {{Text|255|#F580B1}}, y {{Cl|AND}} {{Text|255|#F580B1}}, (x {{Cl|XOR}} y) {{Cl|AND}} {{Text|255|#F580B1}}) | |||
{{Cl|NEXT}} | |||
{{Cl|NEXT}} | {{Cl|NEXT}} | ||
'Store background so we can show moveable objects on it | {{Text|<nowiki>'Store background so we can show moveable objects on it</nowiki>|#919191}} | ||
background& = {{Cl|_COPYIMAGE}} | background& = {{Cl|_COPYIMAGE}}({{Text|0|#F580B1}}) | ||
'Treat my alpha values as transparency | {{Text|<nowiki>'Treat my alpha values as transparency</nowiki>|#919191}} | ||
{{Cl|_BLEND}} alphaSprite& | {{Cl|_BLEND}} alphaSprite& | ||
ph = 0 | ph = {{Text|0|#F580B1}} | ||
{{Cl|DO}}: | {{Cl|DO}}: {{Cl|_LIMIT}} {{Text|60|#F580B1}} | ||
x = {{Text|320|#F580B1}} - {{Text|250|#F580B1}} * {{Cl|COS}}(ph) - ({{Cl|_WIDTH (function)|_WIDTH}}(alphaSprite&) \ {{Text|2|#F580B1}}) | |||
y = {{Text|240|#F580B1}} - {{Text|150|#F580B1}} * {{Cl|COS}}(ph * {{Text|1.3|#F580B1}}) - ({{Cl|_HEIGHT}}(alphaSprite&) \ {{Text|2|#F580B1}}) | |||
ph = ph + {{Text|0.03|#F580B1}} | |||
{{Cl|_PUTIMAGE}} , background&, {{Text|0|#F580B1}} | |||
{{Cl|_PUTIMAGE}} (x, y), alphaSprite&, {{Text|0|#F580B1}} | |||
{{Cl|_DISPLAY}} | |||
{{Cl|LOOP | {{Cl|DO...LOOP|LOOP UNTIL}} {{Cl|LEN}}({{Cl|INKEY$}}) | ||
{{CodeEnd}}{{ | {{CodeEnd}} | ||
{{Small|Code by Zom-B}} | |||
''Explanation:'' To make the alpha image, turn alpha blending off. Otherwise PSET blends the pixel to instead of making the sprite transparent. | ''Explanation:'' To make the alpha image, turn alpha blending off. Otherwise PSET blends the pixel to instead of making the sprite transparent. | ||
Latest revision as of 10:46, 24 March 2023
The _DONTBLEND statement turns off 32 bit alpha blending for the current image or screen mode where _BLEND is default.
Syntax
- _DONTBLEND [imageHandle&]
Parameters
- If imageHandle& is omitted, it is assumed to be the current _DESTination write page.
Description
- 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 to make a new surface background _ALPHA 255 or opaque.
- Both _SOURCE and _DEST must have _BLEND enabled, or else colors will NOT blend.
Examples
Example 1: Use _DONTBLEND when you want the 32 bit screen surface to be opaque so that it covers up other backgrounds. CLS works too.
SCREEN _NEWIMAGE(1280, 720, 32) 'CLS _DONTBLEND '<<< comment out to see the difference LINE (100, 100)-(500, 500), _RGB32(255, 255, 0), BF b& = SaveBackground& PRINT "This is just test junk" PRINT PRINT "Hit any key and the text should disappear, leaving us our pretty yellow box." SLEEP RestoreBackground b& END FUNCTION SaveBackground& SaveBackground& = _COPYIMAGE(0) END FUNCTION SUB RestoreBackground (Image AS LONG) _PUTIMAGE , Image, 0 END SUB |
Example 2: Turning off blending to create transparency.
SCREEN _NEWIMAGE(640, 480, 32) alphaSprite& = _NEWIMAGE(64, 64, 32) _DONTBLEND alphaSprite& ' turn off alpha-blending 'Create a simple sprite with transparency _DEST alphaSprite& FOR y = 0 TO 63 FOR x = 0 TO 63 alpha = SQR((x - 32) ^ 2 + (y - 32) ^ 2) / 32 IF alpha < 0 THEN alpha = 0 alpha = (1 - alpha * alpha) 'parabolic curve PSET (x, y), _RGBA32(255, 255, 255, alpha * 255) NEXT NEXT 'Make a simple background texture _DEST 0 FOR y = 1 TO 479 FOR x = 0 TO 639 PSET (x, y), _RGB32(x AND 255, y AND 255, (x XOR y) AND 255) NEXT NEXT 'Store background so we can show moveable objects on it background& = _COPYIMAGE(0) 'Treat my alpha values as transparency _BLEND alphaSprite& ph = 0 DO: _LIMIT 60 x = 320 - 250 * COS(ph) - (_WIDTH(alphaSprite&) \ 2) y = 240 - 150 * COS(ph * 1.3) - (_HEIGHT(alphaSprite&) \ 2) ph = ph + 0.03 _PUTIMAGE , background&, 0 _PUTIMAGE (x, y), alphaSprite&, 0 _DISPLAY LOOP UNTIL LEN(INKEY$) |
Explanation: To make the alpha image, turn alpha blending off. Otherwise PSET blends the pixel to instead of making the sprite transparent.
See also