Drawing onto ITexture

Any particular reason why this isn’t working as expected? It’s suppose to be a white line from the top left corner; down to the bottom right.


local rt = GetRenderTarget( "test", 64, 64, false );
local mat = CreateMaterial( "test", "UnlitGeneric", {
	["$ignorez"] = 1,
	["$vertexcolor"] = 1,
	["$vertexalpha"] = 1,
	["$nolod"] = 1,
	["$basetexture"] = rt:GetName()
});


local last = render.GetRenderTarget();

render.SetRenderTarget( rt );
render.SetViewPort( 0, 0, 64, 64 );

render.Clear( 0, 0, 0, 255 );
render.ClearDepth();

surface.SetDrawColor( Color( 255, 255, 255 ) );
surface.DrawLine( 0, 0, 64, 64 );

render.SetRenderTarget( last );
render.SetViewPort( 0, 0, ScrW(), ScrH() );


hook.Add( "HUDPaint", "Test", function()
	surface.SetDrawColor( color_white );
	surface.SetMaterial( mat );
	surface.DrawTexturedRect( 128, 128, 256, 256 );
end );

http://i.troll.ws/8d1762a4.png

Try wrapping the drawing code in cam.Start2D() and cam.End2D()

Worked perfectly.

http://puu.sh/6gcOr/d3efa6824a.png

Please accept your payment in lucky screwdriver.

http://puu.sh/6gd0e/031007d0da.png