DxCreateTexture: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:
==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
element dxCreateTexture ( string filepath )
element dxCreateTexture ( string filepath [, string textureFormat = "argb", bool mipmaps = true ] )
element dxCreateTexture ( string pixels [, string textureFormat = "argb", bool mipmaps = true ] )
element dxCreateTexture ( int width, int height [, string textureFormat ] )
</syntaxhighlight>  
</syntaxhighlight>  


===Required Arguments===  
===Required Arguments===
*'''filepath:''' The filepath of the image. (.dds images are also supported). Image files should ideally have dimensions that are a power of two, to prevent possible blurring.
*'''filepath:''' The filepath of the image. (.bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga images are supported). Image files should ideally have dimensions that are a power of two, to prevent possible blurring.
or
*'''pixels:''' [[Texture_pixels|Pixels]] containing image data. ('plain', 'jpeg' or 'png' pixels can be used here)
or
*'''width:''' Required width
*'''height :''' Required height


===Returns===
===Optional Arguments===
*'''textureFormat :''' Desired texture format
**''''argb'''' : ARGB uncompressed 32 bit color (default)
**''''dxt1'''' : DXT1 compressed - Can take a fraction of a second longer to load (unless the file is already a DXT1 .dds). Uses 8 times less memory than ARGB and can speed up drawing. Quality not as good and does not support alpha blending.
**''''dxt3'''' : DXT3 compressed - Can take a fraction of a second longer to load (unless the file is already a DXT3 .dds). Uses 4 times less memory than ARGB and can speed up drawing. Quality better than DXT1 and supports smooth alpha blending.
**''''dxt5'''' : DXT5 compressed - Can take a fraction of a second longer to load (unless the file is already a DXT3 .dds). Uses 4 times less memory than ARGB and can speed up drawing. Quality better than DXT1 and supports crisp alpha blending.
*'''mipmaps :''' True to create a mip-map chain so the texture looks good when drawn at various sizes.
 
==Returns==
Returns a [[texture]] if successful, ''false'' if invalid arguments were passed to the function.
Returns a [[texture]] if successful, ''false'' if invalid arguments were passed to the function.



Revision as of 22:39, 24 January 2012

This function creates a texture element that can be used in the dxDraw functions

Syntax

element dxCreateTexture ( string filepath [, string textureFormat = "argb", bool mipmaps = true ] )
element dxCreateTexture ( string pixels [, string textureFormat = "argb", bool mipmaps = true ] )
element dxCreateTexture ( int width, int height [, string textureFormat ] )

Required Arguments

  • filepath: The filepath of the image. (.bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga images are supported). Image files should ideally have dimensions that are a power of two, to prevent possible blurring.

or

  • pixels: Pixels containing image data. ('plain', 'jpeg' or 'png' pixels can be used here)

or

  • width: Required width
  • height : Required height

Optional Arguments

  • textureFormat : Desired texture format
    • 'argb' : ARGB uncompressed 32 bit color (default)
    • 'dxt1' : DXT1 compressed - Can take a fraction of a second longer to load (unless the file is already a DXT1 .dds). Uses 8 times less memory than ARGB and can speed up drawing. Quality not as good and does not support alpha blending.
    • 'dxt3' : DXT3 compressed - Can take a fraction of a second longer to load (unless the file is already a DXT3 .dds). Uses 4 times less memory than ARGB and can speed up drawing. Quality better than DXT1 and supports smooth alpha blending.
    • 'dxt5' : DXT5 compressed - Can take a fraction of a second longer to load (unless the file is already a DXT3 .dds). Uses 4 times less memory than ARGB and can speed up drawing. Quality better than DXT1 and supports crisp alpha blending.
  • mipmaps : True to create a mip-map chain so the texture looks good when drawn at various sizes.

Returns

Returns a texture if successful, false if invalid arguments were passed to the function.

Example

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

-- Use 'toggle' command to switch image on and off
addCommandHandler( "toggle",
    function()
        if not myImage then
            myImage = dxCreateTexture( "moonpig.png" )  -- Create texture
        else        
            destroyElement( myImage )                 -- Destroy texture
            myImage = nil
        end
    end
)

See Also