DxSetBlendMode: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 13: Line 13:
**'''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.
<div style="padding-left:19px;">
{{New feature/item|4.0133|1.3.0|4425|
{{New feature/item|4.0133|1.3.0|4425|
**'''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.
}}
}}
</div>


==Returns==
==Returns==
Line 25: Line 27:
local myRenderTarget = dxCreateRenderTarget(500, 500, true)
local myRenderTarget = dxCreateRenderTarget(500, 500, true)


--
-- Function to draw text to our render target texture when the 'r' key is pressed
-- Function to draw text to our render target texture when the 'r' key is pressed
--
function updateRenderTarget()
function updateRenderTarget()
     dxSetRenderTarget(myRenderTarget, true)
     dxSetRenderTarget(myRenderTarget, true)
Line 32: Line 36:
     dxDrawText("Testing "..getTickCount(), 0, 0, 0, 0, tocolor(255, 255, 255, 255), 2, "Verdana")
     dxDrawText("Testing "..getTickCount(), 0, 0, 0, 0, tocolor(255, 255, 255, 255), 2, "Verdana")


     dxSetBlendMode("blend") -- Restore default blending
     dxSetBlendMode("blend")         -- Restore default blending
     dxSetRenderTarget()     -- Restore default render target
     dxSetRenderTarget()             -- Restore default render target
end
end
bindKey("r", "down", updateRenderTarget )
bindKey("r", "down", updateRenderTarget )


--
-- Display render target contents
-- Display render target contents
--
addEventHandler("onClientRender", root,
addEventHandler("onClientRender", root,
     function()
     function()
         dxSetBlendMode("add")   -- Set 'add' when drawing the render target on the screen
         dxSetBlendMode("add")       -- Set 'add' when drawing the render target on the screen
         dxDrawImage(100, 200, 500, 500, myRenderTarget, -10)
         dxDrawImage(100, 200, 500, 500, myRenderTarget, -10)
         dxSetBlendMode("blend") -- Restore default blending
         dxSetBlendMode("blend")     -- Restore default blending
     end
     end
)
)

Revision as of 00:07, 7 May 2013

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. The 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.
ADDED/UPDATED IN VERSION 1.3.0 r4425:
  • 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

This 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, "Verdana")

    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
)

Requirements

This template will be deleted.

Changelog

Version Description
1.3.0-9.04425 Added overwrite

See Also