WEAPON/RenderScreen

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(There's no need for that information.)
(Added example)
Line 1: Line 1:
 
{{Hook
 
{{Hook
|Name=RenderScreen
+
|Description=Called every frame to render screens.
|Parent=WEAPON
+
|Description=Called every frame to render screens. SWEP alternative of {{HookFunction|GM|DrawMonitors}}?
+
 
|Realm=Client
 
|Realm=Client
 +
|Predicted=No
 +
}}
 +
{{Example
 +
|Description=Renders the image and scrolling text on the Tool Gun.
 +
|Code=--[[---------------------------------------------------------
 +
We use this opportunity to draw to the toolmode
 +
screen's rendertarget texture.
 +
-----------------------------------------------------------]]
 +
function SWEP:RenderScreen()
 +
 +
local TEX_SIZE = 256
 +
local mode = GetConVarString( "gmod_toolmode" )
 +
local oldW = ScrW()
 +
local oldH = ScrH()
 +
 +
-- Set the material of the screen to our render target
 +
matScreen:SetTexture( "$basetexture", RTTexture )
 +
 +
local OldRT = render.GetRenderTarget()
 +
 +
-- Set up our view for drawing to the texture
 +
render.SetRenderTarget( RTTexture )
 +
render.SetViewPort( 0, 0, TEX_SIZE, TEX_SIZE )
 +
cam.Start2D()
 +
 +
-- Background
 +
surface.SetDrawColor( 255, 255, 255, 255 )
 +
surface.SetTexture( txBackground )
 +
surface.DrawTexturedRect( 0, 0, TEX_SIZE, TEX_SIZE )
 +
 +
-- Give our toolmode the opportunity to override the drawing
 +
if ( self:GetToolObject() && self:GetToolObject().DrawToolScreen ) then
 +
 +
self:GetToolObject():DrawToolScreen( TEX_SIZE, TEX_SIZE )
 +
 +
else
 +
 +
surface.SetFont( "GModToolScreen" )
 +
DrawScrollingText( "#tool." .. mode .. ".name", 104, TEX_SIZE )
 +
 +
end
 +
 +
cam.End2D()
 +
render.SetRenderTarget( OldRT )
 +
render.SetViewPort( 0, 0, oldW, oldH )
 +
 +
end
 
}}
 
}}

Revision as of 12:26, 26 January 2017

 WEAPON:RenderScreen( )

Description

Called every frame to render screens.

Examples

Example

Renders the image and scrolling text on the Tool Gun.

--[[---------------------------------------------------------
	We use this opportunity to draw to the toolmode
		screen's rendertarget texture.
-----------------------------------------------------------]]
function SWEP:RenderScreen()

	local TEX_SIZE = 256
	local mode = GetConVarString( "gmod_toolmode" )
	local oldW = ScrW()
	local oldH = ScrH()

	-- Set the material of the screen to our render target
	matScreen:SetTexture( "$basetexture", RTTexture )

	local OldRT = render.GetRenderTarget()

	-- Set up our view for drawing to the texture
	render.SetRenderTarget( RTTexture )
	render.SetViewPort( 0, 0, TEX_SIZE, TEX_SIZE )
	cam.Start2D()

		-- Background
		surface.SetDrawColor( 255, 255, 255, 255 )
		surface.SetTexture( txBackground )
		surface.DrawTexturedRect( 0, 0, TEX_SIZE, TEX_SIZE )

		-- Give our toolmode the opportunity to override the drawing
		if ( self:GetToolObject() && self:GetToolObject().DrawToolScreen ) then

			self:GetToolObject():DrawToolScreen( TEX_SIZE, TEX_SIZE )

		else

			surface.SetFont( "GModToolScreen" )
			DrawScrollingText( "#tool." .. mode .. ".name", 104, TEX_SIZE )

		end

	cam.End2D()
	render.SetRenderTarget( OldRT )
	render.SetViewPort( 0, 0, oldW, oldH )

end


Personal tools
Navigation