DxCreateShader: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:
Only available in 1.1
Only available in 1.1
}}
}}
This function creates a [[shader]] element that can be used in the dxDraw functions.
This function creates a [[shader]] element that can be used in the dxDraw functions. Successful shader creation is not guaranteed unless the [[shader|Effect File]] contains a fallback technique which will work on every PC in the universe.


Note that successful [[shader]] creation is not guaranteed unless the [[shader|Effect File]] contains a fallback technique which will work on every PC in the universe. You should always check to see if this function has returned false.
=====It is highly recommended that [[dxSetTestMode]] is used when writing and testing scripts using dxCreateShader.=====


==Syntax==  
==Syntax==  
Line 17: Line 17:


===Returns===
===Returns===
*'''element:''' A [[shader]] element if successful, ''false'' if invalid arguments were passed to the function.
*'''element:''' A [[shader]] element if successful, ''false'' if invalid arguments were passed to the function. '''You should always check to see if this function has returned false.'''
*'''string:''' The name of the technique that will be used.
*'''string:''' The name of the technique that will be used.



Revision as of 06:29, 23 August 2011

Only available in 1.1 This function creates a shader element that can be used in the dxDraw functions. Successful shader creation is not guaranteed unless the Effect File contains a fallback technique which will work on every PC in the universe.

It is highly recommended that dxSetTestMode is used when writing and testing scripts using dxCreateShader.

Syntax

element, string dxCreateShader ( string filepath )

Required Arguments

Returns

  • element: A shader element if successful, false if invalid arguments were passed to the function. You should always check to see if this function has returned false.
  • string: The name of the technique that will be used.

Example

addEventHandler( "onClientRender", root,
    function()
        if myShader then
            dxDrawImage( 100, 350, 300, 350, myShader )
        end
    end
)

-- Use 'toggle' command to switch shader on and off
addCommandHandler( "toggle",
    function()
        if not myShader then
            myShader = dxCreateShader( "fancything.fx" )  -- Create shader
        else        
            destroyElement( myShader )                    -- Destroy shader
            myShader = nil
        end
    end
)

See Also