mirror of
https://github.com/QB64Official/qb64.git
synced 2024-08-31 12:20:16 +00:00
101 lines
No EOL
3.3 KiB
Text
101 lines
No EOL
3.3 KiB
Text
{{DISPLAYTITLE:_DONTBLEND}}
|
|
The [[_DONTBLEND]] statement turns off 32 bit alpha blending for the current image or screen mode where [[_BLEND]] is default.
|
|
|
|
|
|
{{PageSyntax}}
|
|
: [[_DONTBLEND]] [{{Parameter|imageHandle&}}]
|
|
|
|
|
|
{{Parameters}}
|
|
* If {{Parameter|imageHandle&}} is omitted, it is assumed to be the current [[_DEST]]ination write page.
|
|
|
|
|
|
{{PageDescription}}
|
|
* If {{Parameter|imageHandle&}} is not valid, an [[ERROR Codes|Invalid handle]] error will occur.
|
|
* [[_DONTBLEND]] is faster than the default [[_BLEND]] 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.
|
|
|
|
|
|
{{PageExamples}}
|
|
''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}} '' ''
|
|
{{Cl|SCREEN}} {{Cl|_NEWIMAGE}}(1280, 720, 32)
|
|
'{{Cl|CLS}}
|
|
{{Cl|_DONTBLEND}} '<<< comment out to see the difference
|
|
|
|
{{Cl|LINE}} (100, 100)-(500, 500), {{Cl|_RGB32}}(255, 255, 0), BF
|
|
|
|
b& = SaveBackground&
|
|
|
|
{{Cl|PRINT}} "This is just test junk"
|
|
{{Cl|PRINT}}
|
|
{{Cl|PRINT}} "Hit any key and the text should disappear, leaving us our pretty yellow box."
|
|
{{Cl|SLEEP}}
|
|
RestoreBackground b&
|
|
|
|
{{Cl|END}}
|
|
|
|
{{Cl|FUNCTION}} SaveBackground&
|
|
SaveBackground& = {{Cl|_COPYIMAGE}}(0)
|
|
{{Cl|END FUNCTION}}
|
|
|
|
{{Cl|SUB}} RestoreBackground (Image {{Cl|AS}} {{Cl|LONG}})
|
|
{{Cl|_PUTIMAGE}} (200, 200), Image, 0
|
|
{{Cl|END SUB}} '' ''
|
|
{{CodeEnd}}
|
|
|
|
|
|
''Example 2:'' Turning off blending to create transparency.
|
|
{{CodeStart}}
|
|
|
|
{{Cl|SCREEN (statement)|SCREEN}} {{Cl|_NEWIMAGE}}(640, 480, 32)
|
|
alphaSprite& = {{Cl|_NEWIMAGE}}(64, 64, 32)
|
|
|
|
{{Cl|_DONTBLEND}} alphaSprite& ' turn off alpha-blending
|
|
|
|
'Create a simple sprite with transparency
|
|
{{Cl|_DEST}} alphaSprite&
|
|
{{Cl|FOR}} y = 0 {{Cl|TO}} 63
|
|
{{Cl|FOR}} x = 0 {{Cl|TO}} 63
|
|
alpha = {{Cl|SQR}}((x - 32) ^ 2 + (y - 32) ^ 2) / 32
|
|
{{Cl|IF}} alpha < 0 {{Cl|THEN}} alpha = 0
|
|
alpha = (1 - alpha * alpha) 'parabolic curve
|
|
{{Cl|PSET}} (x, y), {{Cl|_RGBA32}}(255, 255, 255, alpha * 255)
|
|
{{Cl|NEXT}}
|
|
{{Cl|NEXT}}
|
|
|
|
'Make a simple background texture
|
|
{{Cl|_DEST}} 0
|
|
{{Cl|FOR}} y = 1 {{Cl|TO}} 479
|
|
{{Cl|FOR}} x = 0 {{Cl|TO}} 639
|
|
{{Cl|PSET}} (x, y), {{Cl|_RGB32}}(x {{Cl|AND (boolean)|AND}} 255, y {{Cl|AND (boolean)|AND}} 255, (x {{Cl|XOR (boolean)|XOR}} y) {{Cl|AND (boolean)|AND}} 255)
|
|
{{Cl|NEXT}}
|
|
{{Cl|NEXT}}
|
|
|
|
'Store background so we can show moveable objects on it
|
|
background& = {{Cl|_COPYIMAGE}}
|
|
|
|
'Treat my alpha values as transparency
|
|
{{Cl|_BLEND}} alphaSprite&
|
|
|
|
ph = 0
|
|
{{Cl|DO}}: {{Cl|_LIMIT}} 60
|
|
x = 320 - 250 * {{Cl|COS}}(ph) - ({{Cl|_WIDTH (function)|_WIDTH}}(alphaSprite&) \ 2)
|
|
y = 240 - 150 * {{Cl|COS}}(ph * 1.3) - ({{Cl|_HEIGHT}}(alphaSprite&) \ 2)
|
|
ph = ph + 0.03
|
|
{{Cl|_PUTIMAGE}} , background&, 0
|
|
{{Cl|_PUTIMAGE}} (x, y), alphaSprite&, 0
|
|
{{Cl|_DISPLAY}}
|
|
{{Cl|LOOP}} {{Cl|UNTIL}} {{Cl|LEN}}({{Cl|INKEY$}}) '' ''
|
|
{{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.
|
|
|
|
|
|
{{PageSeeAlso}}
|
|
* [[_BLEND]]
|
|
* [[_BLEND (function)]]
|
|
* [[Images]]
|
|
|
|
|
|
{{PageNavigation}} |