surface.DrawTexturedRectUV
Example
Demonstrates the function usage.
local mat = Material( "gui/tool.png" )
hook.Add( "HUDPaint", "DrawTexturedRectUV_example1", function()
surface.SetDrawColor( color_white )
surface.SetMaterial( mat )
surface.DrawTexturedRect( 25, 25, 100, 100 )
surface.DrawTexturedRectUV( 25, 130, 100, 100, 0, 0, 1, 1 ) -- Exactly same as above line
-- Draws right half of the texture
-- Note that we also change the width of the rectangle to avoid stetcing of the texture
-- This is for demonstration purposes, you can do whatever it is you need
surface.DrawTexturedRectUV( 130, 130, 50, 100, 0.5, 0, 1, 1 )
end )
Example
Paints repeated texture over a panel
local mat = Material( "icon16/box.png", "noclamp" )
function PANEL:Paint( w, h )
-- Size of your texture, texW - width, texH - height
local texW = 16
local texH = 16
surface.SetMaterial( mat )
surface.SetDrawColor( color_white )
surface.DrawTexturedRectUV( 0, 0, w, h, 0, 0, w / texW, h / texH )
end