DxSetRenderTarget: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(8 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
{{Client function}} | {{Client function}} | ||
__NOTOC__ | __NOTOC__ | ||
This function changes the drawing destination for the dx functions. It can be used to select a previously created render target, or if called with no arguments, restore drawing directly to the screen. | This function changes the drawing destination for the dx functions. It can be used to select a previously created render target, or if called with no arguments, restore drawing directly to the screen. | ||
Line 12: | Line 9: | ||
If no arguments are supplied, the screen is restored as the drawing destination. | If no arguments are supplied, the screen is restored as the drawing destination. | ||
{{OOP||[[texture|rendertarget]]:setAsTarget}} | |||
===Optional Arguments=== | ===Optional Arguments=== | ||
Line 21: | Line 20: | ||
==Usage restrictions== | ==Usage restrictions== | ||
*Items drawn with ''postGUI'' set to ''true'' will not appear on a custom render target. | |||
{{Deprecated feature|3.0131|1.3.0-9.04431| | |||
*dxSetRenderTarget can only be called during the [[onClientRender]], [[onClientHUDRender]] and [[onClientRestore]] events. | *dxSetRenderTarget can only be called during the [[onClientRender]], [[onClientHUDRender]] and [[onClientRestore]] events. | ||
* | }} | ||
{{New_feature|3.0131|1.3.0-9.04431| | |||
*dxSetRenderTarget can be set at any time as long as <min_mta_version> in [[meta.xml]] is set to at least 1.3.0-9.04431 e.g. '''<min_mta_version client<nowiki>=</nowiki>"1.3.0-9.04431" />''' | |||
}} | |||
==Example== | ==Example== | ||
Line 44: | Line 48: | ||
) | ) | ||
</syntaxhighlight> | </syntaxhighlight> | ||
This example shows how you can prepare render target contents at anytime (from client version 1.3.0-9.04431) | |||
<syntaxhighlight lang="lua"> | |||
addEventHandler("onClientResourceStart", resourceRoot, | |||
function() | |||
myRenderTarget = dxCreateRenderTarget( 80, 100 ) -- Create a render target texture which is 80 x 100 pixels | |||
dxSetRenderTarget( myRenderTarget ) -- Select custom render target for drawing | |||
dxDrawRectangle ( 2, 2, 60, 60, tocolor(255,255,0) ) -- Draw anything you like (to the render target) | |||
dxDrawText ( "Hello", 10, 20 ) | |||
dxDrawText ( "This is", 10, 40 ) | |||
dxDrawText ( "Amazing", 10, 60 ) | |||
dxSetRenderTarget() -- Unselect custom render target | |||
end | |||
) | |||
addEventHandler( "onClientRender", root, | |||
function() | |||
if myRenderTarget then | |||
dxDrawImage ( 100, 200, 80, 100, myRenderTarget ) -- Draw myRenderTarget content to the screen | |||
end | |||
end | |||
) | |||
</syntaxhighlight> | |||
==Changelog== | |||
{{ChangelogHeader}} | |||
{{ChangelogItem|1.3.0-9.04431|Removed restrictions on when dxSetRenderTarget could be called}} | |||
==See Also== | ==See Also== | ||
{{Drawing_functions}} | {{Drawing_functions}} | ||
[[hu:dxSetRenderTarget]] |
Latest revision as of 20:40, 23 December 2018
This function changes the drawing destination for the dx functions. It can be used to select a previously created render target, or if called with no arguments, restore drawing directly to the screen.
Syntax
bool dxSetRenderTarget ( [ element renderTarget, bool clear = false ] )
If no arguments are supplied, the screen is restored as the drawing destination.
OOP Syntax Help! I don't understand this!
- Method: rendertarget:setAsTarget(...)
Optional Arguments
- renderTarget: The render target element whose pixels we want to draw on.
- clear: If set to true, the render target will also be cleared.
Returns
Returns true if the render target was successfully changed, false otherwise.
Usage restrictions
- Items drawn with postGUI set to true will not appear on a custom render target.
- dxSetRenderTarget can be set at any time as long as <min_mta_version> in meta.xml is set to at least 1.3.0-9.04431 e.g. <min_mta_version client="1.3.0-9.04431" />
Example
addEventHandler("onClientResourceStart", resourceRoot, function() myRenderTarget = dxCreateRenderTarget( 80, 100 ) -- Create a render target texture which is 80 x 100 pixels end ) addEventHandler( "onClientRender", root, function() if myRenderTarget then dxSetRenderTarget( myRenderTarget ) -- Select custom render target dxDrawText ( "Hello", 10, 20 ) -- The message 'Hello' will be drawn on myRenderTarget dxSetRenderTarget() -- Select default render target dxDrawText ( "Goodbye", 10, 20 ) -- The message 'Goodbye' will be drawn directly to the screen end end )
This example shows how you can prepare render target contents at anytime (from client version 1.3.0-9.04431)
addEventHandler("onClientResourceStart", resourceRoot, function() myRenderTarget = dxCreateRenderTarget( 80, 100 ) -- Create a render target texture which is 80 x 100 pixels dxSetRenderTarget( myRenderTarget ) -- Select custom render target for drawing dxDrawRectangle ( 2, 2, 60, 60, tocolor(255,255,0) ) -- Draw anything you like (to the render target) dxDrawText ( "Hello", 10, 20 ) dxDrawText ( "This is", 10, 40 ) dxDrawText ( "Amazing", 10, 60 ) dxSetRenderTarget() -- Unselect custom render target end ) addEventHandler( "onClientRender", root, function() if myRenderTarget then dxDrawImage ( 100, 200, 80, 100, myRenderTarget ) -- Draw myRenderTarget content to the screen end end )
Changelog
Version | Description |
---|
1.3.0-9.04431 | Removed restrictions on when dxSetRenderTarget could be called |
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