Can you draw on the toolgun screen?

I was thinking about having a radar displayed on a weapon, like the toolgun screen.

Is it possible? and if yes, how difficult would that be?

Yep, it’s actually really easy. Here’s the toolgun’s source.
[lua]
local matScreen = Material( “models/weapons/v_toolgun/screen” )
local txidScreen = surface.GetTextureID( “models/weapons/v_toolgun/screen” )
local txRotating = surface.GetTextureID( “pp/fb” )

local txBackground = surface.GetTextureID( “models/weapons/v_toolgun/screen_bg” )

// GetRenderTarget returns the texture if it exists, or creates it if it doesn’t
local RTTexture = GetRenderTarget( “GModToolgunScreen”, 256, 256 )

surface.CreateFont( “Arial Black”, 82, 1000, true, false, “GModToolScreen” )

local function DrawScrollingText( text, y, texwide )

	local w, h = surface.GetTextSize( text  )
	w = w + 64
	
	local x = math.fmod( CurTime() * 400, w ) * -1;
	
	while ( x < texwide ) do
	
		surface.SetTextColor( 0, 0, 0, 255 )
		surface.SetTextPos( x + 3, y + 3 )
		surface.DrawText( text )
			
		surface.SetTextColor( 255, 255, 255, 255 )
		surface.SetTextPos( x, y )
		surface.DrawText( text )
		
		x = x + w
		
	end

end

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

local TEX_SIZE = 256
local mode 	= gmod_toolmode:GetString()
local NewRT = RTTexture
local oldW = ScrW()
local oldH = ScrH()

// Set the material of the screen to our render target
matScreen:SetMaterialTexture( "$basetexture", NewRT )

local OldRT = render.GetRenderTarget();

// Set up our view for drawing to the texture
render.SetRenderTarget( NewRT )
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", 64, TEX_SIZE )
			
	end

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

end[/lua]

interesting it “appears” i could easily convert my radar hudpaint to the toolgun screen… will have to see about this…

Okay this is actually quite simple :D, and fun :slight_smile:
I don’t think a radar can get cooler than that :smiley:

http://i39.tinypic.com/24xkxec_th.jpg

I had some trouble figuring out that the vmt files needed to be changed in order to display properly on models.