DxDrawPrimitive: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Initial version of dxDrawPrimitive)
 
(9 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Client function}}  
{{Client function}}  
This function draws a 2D primitive shape across the screen - rendered for one frame. This should be used in conjunction with [[onClientRender]] in order to display continuously.
{{New feature/item|3.0157|1.5.6|14370|This function draws a 2D primitive shape across the screen - rendered for one frame. This should be used in conjunction with [[onClientRender]] in order to display continuously.}}


==Syntax==  
==Syntax==  
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool dxDrawPrimitive ( primitiveType pType, bool postGUI, table vertice1, [table vertice2, ...] )
bool dxDrawPrimitive ( string pType, bool postGUI, table vertice1 [, table vertice2, ...] )
</syntaxhighlight>
</syntaxhighlight>


Line 14: Line 14:


==Allowed types==
==Allowed types==
[[Image:MTAsa_primitives.png|thumb|240px|Availible primitive types.]]
[[Image:MTAsa_primitives.png|thumb|240px|Available primitive types.]]
More info on primitives may be found on [https://msdn.microsoft.com/en-us/library/windows/desktop/bb147291(v=vs.85).aspx this MSDN site]  
More info on primitives may be found on [https://msdn.microsoft.com/en-us/library/windows/desktop/bb147291(v=vs.85).aspx this MSDN site]  
* '''pointlist:''' Renders the vertices as a collection of isolated points.
* '''pointlist:''' Renders the vertices as a collection of isolated points.
Line 31: Line 31:
Returns a ''true'' if the operation was successful, ''false'' otherwise.
Returns a ''true'' if the operation was successful, ''false'' otherwise.


==Example==  
==Example==
This is a small example that creates trianglefan primitive with vertices in places that user clicks. It assigns every vertice random color.
This is a small example that creates trianglefan primitive with vertices in places that user clicks. It assigns every vertice random color.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
local vertices = {}
local vertices = {}
function onClick(btn,state,x,y)
function onClick(btn, state, x, y)
if btn ~= "left" then return end
if btn ~= "left" then return end
if state ~= "up" then return end
if state ~= "up" then return end
local vertice = {x, y, tocolor(math.random(0,255), math.random(0,255), math.random(0,255))}
local vertice = {x, y, tocolor(math.random(255), math.random(255), math.random(255))}
table.insert(vertices, vertice)
table.insert(vertices, vertice)
end
end
Line 51: Line 51:
==See Also==
==See Also==
{{Drawing_functions}}
{{Drawing_functions}}
[[hu:dxDrawPrimitive]]

Revision as of 21:02, 5 April 2020

This function draws a 2D primitive shape across the screen - rendered for one frame. This should be used in conjunction with onClientRender in order to display continuously.

Syntax

bool dxDrawPrimitive ( string pType, bool postGUI, table vertice1 [, table vertice2, ...] )

Required Arguments

  • pType: Type of primitive to be drawn.
  • postGUI: A bool representing whether the line should be drawn on top of or behind any ingame GUI (rendered by CEGUI).
  • vertices: Tables representing each primitive vertice, required amount of them is determined by primitive type.

Allowed types

Available primitive types.

More info on primitives may be found on this MSDN site

  • pointlist: Renders the vertices as a collection of isolated points.
  • linelist: Renders the vertices as a list of isolated straight line segments.
  • linestrip: Renders the vertices as a single polyline.
  • trianglelist: Renders the specified vertices as a sequence of isolated triangles. Each group of three vertices defines a separate triangle.
  • trianglestrip: Renders the vertices as a triangle strip.
  • trianglefan: Renders the vertices as a triangle fan.

Vertices format

  • posX: An float representing the absolute X position of the vertice, represented by pixels on the screen.
  • posY: An float representing the absolute Y position of the vertice, represented by pixels on the screen.
  • color (optional): An integer of the hex color, produced using tocolor or 0xAARRGGBB (AA = alpha, RR = red, GG = green, BB = blue). If it's not specified, white color is used.

Returns

Returns a true if the operation was successful, false otherwise.

Example

This is a small example that creates trianglefan primitive with vertices in places that user clicks. It assigns every vertice random color.

local vertices = {}
function onClick(btn, state, x, y)
	if btn ~= "left" then return end
	if state ~= "up" then return end
	local vertice = {x, y, tocolor(math.random(255), math.random(255), math.random(255))}
	table.insert(vertices, vertice)
end
addEventHandler("onClientClick", root, onClick)

function draw()
	dxDrawPrimitive("trianglefan", true, unpack(vertices))
end
addEventHandler("onClientPreRender", root, draw)

See Also