Revision Difference
cam.PushModelMatrix#561632
<function name="PushModelMatrix" parent="cam" type="libraryfunc">
<description>
Pushes the specified matrix onto the render matrix stack. Unlike opengl, this will replace the current model matrix.
<note>This does not work with <page>cam.Start3D2D</page> if `multiply` is false.</note>
<warning>When used in the Paint function of a panel, if you want to rely on the top-left position of the panel, you must use <page>VMatrix:Translate</page> with the (0, 0) position of the panel relative to the screen.</warning>
</description>
<realm>Client</realm>
<args>
<arg name="matrix" type="VMatrix">The matrix to push.</arg>
<arg name="multiply" type="boolean" default="false">If set, multiplies given matrix with currently active matrix (<page>cam.GetModelMatrix</page>) before pushing.</arg>
</args>
</function>
<example>
<description>Simple function to draw rotated and/or scaled text.</description>
<code>
local vector_one = Vector( 1, 1, 1 )
function draw.RotatedText( text, font, x, y, color, ang, scale )
render.PushFilterMag( TEXFILTER.ANISOTROPIC )
render.PushFilterMin( TEXFILTER.ANISOTROPIC )
local m = Matrix()
m:Translate( Vector( x, y, 0 ) )
m:Rotate( Angle( 0, ang, 0 ) )
m:Scale( vector_one * ( scale or 1 ) )
surface.SetFont( font )
local w, h = surface.GetTextSize( text )
m:Translate( Vector( -w / 2, -h / 2, 0 ) )
cam.PushModelMatrix( m )
cam.PushModelMatrix( m, true )
draw.DrawText( text, font, 0, 0, color )
cam.PopModelMatrix()
render.PopFilterMag()
render.PopFilterMin()
end
hook.Add("HUDPaint", "2d rotation test", function()
local w, h = ScrW(), ScrH()
local ang = RealTime() * 50
local scale = ( math.sin( ang / 10 ) + 2 ) * 0.5
draw.RotatedText( "My fancy Rotating Text", "DermaLarge", w / 2, h / 2, color_white, ang, scale )
end)
</code>
<output>
<upload src="70c/8dc53b786182f21.mp4" size="411916" name="hl2_QmJKFXNAVS.mp4" />
</output>
</example>