Does anyone have code which accomplishes this? Right now I'm doing this:
local cid_mat = CreateMaterial("cid_model","VertexLitGeneric",{["$basetexture"] = "models/Dorado/1texture"}) --this basetexture is the basetexture used by the model by default.
--this is the operational code:
function model:PreDrawModel(ent)
local base = cid_mat:GetTexture("$basetexture")
render.PushRenderTarget(base,0,0,256,512)
render.Clear(255,255,255,255)
cam.Start2D()
draw.RoundedBox(0,10,10,50,50,color_white) --try to draw a white box. no success.
cam.End2D()
render.PopRenderTarget()
cid_mat:SetTexture("$basetexture",base)
ent:SetMaterial("!cid_model")
end
I'll accept hacky answers too.
Here is how gmod_tool does it: garrysmod/cl_viewscreen.lua at 784cd57576d85712fa13a7cea3a9523b4..
Think you need to use a rendertarget GetRenderTarget( name, width, height)
The toolgun has a dedicated texture just for the screen, so if you overwrite it completely it doesn't fuck up the rest of the model's texture. Any way I can render my stuff on top of the existing texture for my model?
Figured it out. For some reason render.CopyTexture likes to copy the screenspace texture to the destination rather than the one you specify.
I used the following code:
--Items.CID is a DModelPanel.
local cid_mat = Material( "models/Dorado/4texture" )
local rt = CLIENT and GetRenderTarget("cid_texture",256,512,false)
local view = {
type = "3D",
origin = Vector(75,-1,56.5),
angles = Angle(0,180,0),
x = 60,
y = 0,
w = 256,
h = 256,
aspect = 1,
fov = 30,
}
hook.Add("PostRender","cit_cid",function(a,b)
if b then return end
if !IsValid(Items.CID) then return end
CID_MAT_TEX = CID_MAT_TEX or cid_mat:GetTexture("$basetexture") --only load this once since we change it after the first time.
local x,y = Items.CID:LocalToScreen(0,0)
cid_mat:SetTexture("$basetexture",rt)
render.PushRenderTarget(rt,x/ScrW(),y/ScrH(),256,512)
render.Clear(0,0,0,255,true,true)
render.DrawTextureToScreenRect(CID_MAT_TEX,0,0,256,512) --copy default model texture to our RT
cam.Start2D()
surface.SetDrawColor(Color(255,0,0))
surface.SetDrawColor(Color(0,0,0,200))
surface.DrawRect(160,20,70,80)
cam.End2D()
--draw model.
render.SuppressEngineLighting(true)
render.MaterialOverride(nil)
render.ClearDepth()
render.SetScissorRect(160,20,160+70,20+80,true)
cam.Start(view) -- Draw a 3d model.
render.Model({model = LocalPlayer():GetModel(),pos=Vector(0,0,0),ang=Angle(0,0,0)})
cam.End()
render.SetScissorRect(0,0,0,0,false)
render.SuppressEngineLighting(false)
render.PopRenderTarget()
Items.CID.Entity:SetSubMaterial(0,cid_mat:GetName())
-- render.DrawTextureToScreenRect(rt,ScrW()-256,0,256,512) --debug. Renders it on the screen.
end)
Sorry, you need to Log In to post a reply to this thread.