Can't set colour of quad?

So I’m drawing this quad, but it always turns out white no matter what. Code:

local matWhite = Material( “color/white” )

// --------------------------------------------------------------------------------
// Draw3D2DLine - Renders a line in 3D space
// --------------------------------------------------------------------------------
function render.Draw3D2DLine( startpos, endpos, normal, colour, thickness )
// Calculate coords
local dir = (endpos-startpos):Normalize()
local dir_right = dir:Angle():Right()
local dir_left = dir_right*-1
local c1 = startpos + (dir_leftthickness0.5)
local c2 = startpos + (dir_rightthickness0.5)
local c3 = endpos + (dir_leftthickness0.5)
local c4 = endpos + (dir_rightthickness0.5)

// Render
render.SetMaterial( matWhite )
render.SuppressEngineLighting( true )
 render.SetColorModulation( 0, 1, 0 )
render.DrawQuad( c1, c3, c4, c2 )
 render.SetColorModulation( 1, 1, 1 )
 render.SuppressEngineLighting( false )



	"$basetexture" "color/white"
	"$vertexalpha" 	1

The line itself draws perfectly in every way apart from the colour.

Now you may be thinking “of course it’s white, you chose the color/white material dumbass” but surely, the color modulation stuff should allow me to manipulate the colour exactly?


Just realised I have no idea why I passed in a parameter called “normal” but oh well.

The “color/white” material is missing the $vertexcolor parameter that would allow you to modulate its rendering color. Copying that VMT, with the added line

$vertexcolor 1

should solve your problem.

Didn’t work. I’m also trying to get alpha to work, which has the same problem.

[lua] render.SetMaterial( matLine )
render.SetBlend( colour.a/255 )
render.SetColorModulation( 0, 1, 0 )
render.DrawQuad( c1, c3, c4, c2 )
render.SetBlend( 1 )[/lua]

	"$basetexture" "color/white"
	"$vertexalpha" 	1
	"$vertexcolor" 	1

I’m passing this colour structure in, if it makes a difference: Color( 250, 250, 150, 180 )

I tried switching the texture too, to random textures like silkicons and stuff but there’s still no color or alpha change.

That is odd. Take a look at DrawQuadEasy—it takes a color parameter, and I’m pretty sure I’ve used that successfully before.

I don’t know id you did take in consideration , there is a color parameter. And I already used it and it works so… yeah. xD

I would’ve suggested the same thing, but DrawQuadEasy doesn’t appear to take an orientation parameter about its normal, and as he’s trying to draw a line, that isn’t really helpful.

I did try DrawQuadEasy, and although I couldn’t get it to be in the correct orientation like mahalis said, I did manage to get it visible for a few seconds to see that I had exactly the same problem with that too. But I’ll mess with it some more, see if I can get the orientation right.

I don’t suppose it’s anything todo with my hardware, my dev machine has a dx8 card?

Are you double positive that every material you use for this is correctly set to $vertexcolor 1? This has happened to me before when using some particles for an effect. $vertexcolor, if you didn’t already know, allows the engine to apply color transformations to a material in real time, allowing you to do what you’ve been wanting.

Good luck :biggrin:


If that’s definitely not the case, I’m not sure what the problem could be. Maybe invite someone who’s directx level is v9 and see if that changes it?

Makes me almost 98% positive that directx 8 doesn’t support the color modulation of rendered quads.

I’ll try it on my main pc (which has a dx9 card) later and see if it works. Thanks for all ya help, anyway.

try using

local col = Vector(0,1,0) --Green
local white = Vector(1,1,1) --white
--put drawing code here

I’ve used this method before and it works pretty well, so I think it’s worth giving it a shot for whatever you’re doing.