DxSetBlendMode: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Fernando187 (talk | contribs) (Remove obsolete Requirements section) |
||
(8 intermediate revisions by 7 users not shown) | |||
Line 1: | Line 1: | ||
{{Client function}} | {{Client function}} | ||
__NOTOC__ | __NOTOC__ | ||
This function sets the current blend mode for the dxDraw functions. Changing the blend mode can increase the quality when drawing text or certain other images to a render target. As a general guide use '''modulate_add''' when drawing text to a render target, and '''add''' when drawing the render target to the screen. Don't forget to restore the default '''blend''' at the end. | This function sets the current blend mode for the dxDraw functions. Changing the blend mode can increase the quality when drawing text or certain other images to a render target. As a general guide use '''modulate_add''' when drawing text to a render target, and '''add''' when drawing the render target to the screen. Don't forget to restore the default '''blend''' at the end - See the example below. | ||
==Syntax== | ==Syntax== | ||
Line 10: | Line 10: | ||
===Required Arguments=== | ===Required Arguments=== | ||
*'''blendMode :''' The blend mode to use which can be one of: | *'''blendMode :''' The blend mode to use which can be one of: | ||
**'''blend:''' The source textures are alpha blended to the screen/render target. | **'''blend:''' The source textures are alpha blended to the screen/render target. This is the default mode for drawing and gives the results we all know and love. | ||
**'''add:''' The source textures are added to the screen/render target. | **'''add:''' The source textures are added to the screen/render target. | ||
**'''modulate_add:''' The source textures are multiplied by the alpha and then added to the screen/render target. | **'''modulate_add:''' The source textures are multiplied by the alpha and then added to the screen/render target. | ||
**'''overwrite :''' The source textures are overwritten. This can be useful for clearing render targets. | **'''overwrite :''' The source textures are overwritten. This can be useful for clearing render targets. | ||
==Returns== | ==Returns== | ||
Returns true if successful, or ''false'' if invalid arguments were passed to the function. | Returns true if successful, or ''false'' if invalid arguments were passed to the function. | ||
==Example== | ==Example== | ||
<section name="Client" class="client" show="true"> | |||
This example shows how to use '''modulate_add''' and '''add''' to avoid quality problems when using a render target: | |||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
-- | local myRenderTarget = dxCreateRenderTarget(500, 500, true) | ||
-- | |||
-- Function to draw text to our render target texture when the 'r' key is pressed | |||
-- | |||
function updateRenderTarget() | |||
dxSetRenderTarget(myRenderTarget, true) | |||
dxSetBlendMode("modulate_add") -- Set 'modulate_add' when drawing stuff on the render target | |||
dxDrawText("Testing "..getTickCount(), 0, 0, 0, 0, tocolor(255, 255, 255, 255), 2, "clear") | |||
dxSetBlendMode("blend") -- Restore default blending | |||
dxSetRenderTarget() -- Restore default render target | |||
end | |||
bindKey("r", "down", updateRenderTarget ) | |||
-- | |||
-- Display render target contents | |||
-- | |||
addEventHandler("onClientRender", root, | |||
function() | |||
dxSetBlendMode("add") -- Set 'add' when drawing the render target on the screen | |||
dxDrawImage(100, 200, 500, 500, myRenderTarget, -10) | |||
dxSetBlendMode("blend") -- Restore default blending | |||
end | |||
) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | |||
==Changelog== | ==Changelog== | ||
Line 35: | Line 58: | ||
{{Drawing_functions}} | {{Drawing_functions}} | ||
[[ | [[hu:dxSetBlendMode]] |
Latest revision as of 17:00, 7 November 2024
This function sets the current blend mode for the dxDraw functions. Changing the blend mode can increase the quality when drawing text or certain other images to a render target. As a general guide use modulate_add when drawing text to a render target, and add when drawing the render target to the screen. Don't forget to restore the default blend at the end - See the example below.
Syntax
bool dxSetBlendMode ( string blendMode )
Required Arguments
- blendMode : The blend mode to use which can be one of:
- blend: The source textures are alpha blended to the screen/render target. This is the default mode for drawing and gives the results we all know and love.
- add: The source textures are added to the screen/render target.
- modulate_add: The source textures are multiplied by the alpha and then added to the screen/render target.
- overwrite : The source textures are overwritten. This can be useful for clearing render targets.
Returns
Returns true if successful, or false if invalid arguments were passed to the function.
Example
Click to collapse [-]
ClientThis example shows how to use modulate_add and add to avoid quality problems when using a render target:
local myRenderTarget = dxCreateRenderTarget(500, 500, true) -- -- Function to draw text to our render target texture when the 'r' key is pressed -- function updateRenderTarget() dxSetRenderTarget(myRenderTarget, true) dxSetBlendMode("modulate_add") -- Set 'modulate_add' when drawing stuff on the render target dxDrawText("Testing "..getTickCount(), 0, 0, 0, 0, tocolor(255, 255, 255, 255), 2, "clear") dxSetBlendMode("blend") -- Restore default blending dxSetRenderTarget() -- Restore default render target end bindKey("r", "down", updateRenderTarget ) -- -- Display render target contents -- addEventHandler("onClientRender", root, function() dxSetBlendMode("add") -- Set 'add' when drawing the render target on the screen dxDrawImage(100, 200, 500, 500, myRenderTarget, -10) dxSetBlendMode("blend") -- Restore default blending end )
Changelog
Version | Description |
---|
1.3.0-9.04425 | Added overwrite |
See Also
- dxConvertPixels
- dxCreateFont
- dxCreateRenderTarget
- dxCreateScreenSource
- dxCreateShader
- dxCreateTexture
- dxDrawCircle
- dxDrawImage
- dxDrawImageSection
- dxDrawLine
- dxDrawLine3D
- dxDrawMaterialLine3D
- dxDrawMaterialPrimitive
- dxDrawMaterialPrimitive3D
- dxDrawMaterialSectionLine3D
- dxDrawPrimitive
- dxDrawPrimitive3D
- dxDrawRectangle
- dxDrawText
- dxDrawWiredSphere
- dxGetBlendMode
- dxGetFontHeight
- dxGetMaterialSize
- dxGetPixelColor
- dxGetPixelsSize
- dxGetPixelsFormat
- dxGetStatus
- dxGetTextSize
- dxGetTextWidth
- dxGetTexturePixels
- dxIsAspectRatioAdjustmentEnabled
- dxSetAspectRatioAdjustmentEnabled
- dxSetBlendMode
- dxSetPixelColor
- dxSetRenderTarget
- dxSetShaderValue
- dxSetShaderTessellation
- dxSetShaderTransform
- dxSetTestMode
- dxSetTextureEdge
- dxSetTexturePixels
- dxUpdateScreenSource