mesh.Color

From GMod Wiki

Jump to: navigation, search
Function
Syntax mesh.Color( Number Red, Number Green, Number Blue, Number Alpha )
Where is this used?
Description:
Defines the color and alpha of the current vertex.
Returns: nil
Part of Library: mesh
Realm: NewerClient.png
BBCode Link: [b][url=http://wiki.garrysmod.com/?title=Mesh.Color]Mesh.Color [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]



Examples

DescriptionDraws a single triangle with one vertex at the entity's origin
Used onNewerClient.png
Code
 
local MaterialWhite = CreateMaterial( "WhiteMaterial", "UnlitGeneric", {	-- Necessary to assign color by vertex
	["$basetexture"] = "color/white",
	["$vertexcolor"] = 1,	-- Necessary to assign color by vertex
	["$vertexalpha"] = 1,	-- Necessary to assign alpha to vertex
	["$model"] = 1
} );
function ENT:Draw()
	self:DrawModel();
 
	local mat = Matrix();
	mat:Translate( self:GetPos() );
	mat:Rotate( self:GetAngles() );
	mat:Scale( Vector( 1, 1, 1 ) * 64 );
 
	render.SetMaterial( MaterialWhite );
 
	cam.PushModelMatrix( mat );
 
		mesh.Begin( MATERIAL_TRIANGLES, 1 );
		--mesh.Begin( MATERIAL_LINE_LOOP, 3 );
 
			mesh.Position( Vector( 0, 0, 0 ) );
			mesh.Normal( Vector( 0, 0, 1 ) );
			mesh.TexCoord( 0, 0, 0 );
			mesh.Color( 255, 0, 0, 255 );
			mesh.AdvanceVertex();
 
			mesh.Position( Vector( 0, 1, 0 ) );
			mesh.Normal( Vector( 0, 0, 1 ) );
			mesh.TexCoord( 0, 1, 0 );
			mesh.Color( 0, 255, 0, 255 );
			mesh.AdvanceVertex();
 
			mesh.Position( Vector( 0, 0, 1 ) );
			mesh.Normal( Vector( 0, 0, 1 ) );
			mesh.TexCoord( 0, 0, 1 );
			mesh.Color( 0, 0, 255, 255 );
			mesh.AdvanceVertex();
 
		mesh.End();
 
	cam.PopModelMatrix();
end
OutputA triangle that rotates with the entity it is being drawn on.


Additional Notes

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox