Problem with render target - it doesnt start itself
3 replies, posted
Hi, I have very very weird problem with making dynamic scope into my swep.I searched a lot and there was one thread about this problem but nobody answered to this and I decieded to answer again. I have simple code for render target
function SWEP:Think()
if ( CLIENT ) then
local old = render.GetRenderTarget( )
local ply = LocalPlayer()
CamData = {}
CamData.angles = ply:GetAimVector():Angle()
CamData.origin = ply:GetShootPos()
CamData.x = 0
CamData.y = 0
CamData.w = 1000
CamData.h = 1000
CamData.fov = 4
CamData.drawviewmodel = false
CamData.drawhud = false
CamData.ortho = false
CamData.dopostprocess = false
render.SetRenderTarget( self.RenderTarget )
cam.Start2D()
render.RenderView(CamData)
surface.SetDrawColor(255, 255, 255, 255)
surface.SetTexture(self.reticle)
surface.DrawTexturedRect(0, 0, 1877, 1070) // dont ask
cam.End2D()
render.SetRenderTarget( old )
end
end
Everything is OK but it dosent start rendering itself. I must make some change in code then save the file and it is rendering. I tried hooking up this to HUDPaint or something similar but problem is the same. Also tried into SWEP:ViewModelDrawn and nothing. What is the problem? I don't know what I'm doing wroing, please help I'm out of ideas....
Because you're doing it in Think hook.
You can draw something in any hook because there's a group of render hooks which you can use for drawing
In your case you need to use something like WEAPON/DrawHUD or WEAPON/DrawHUDBackground
In both functions same thing happens
I today found fix for my problem with not initiating render target... Problem was in variables which I had at top of the file...
I'm posting this for people who is searching for solution. Whole thing looks like this in DrawHUD function:
function SWEP:DrawHUD()
if CLIENT then -- here is the place where these variable must be. It can't be in any other place.
mat = Material( "models/weapons/v_models/SoulSlayer.SR25/rtplaceholder" )
RenderTarget = GetRenderTarget( "L96_Scope", 1024, 1024, false)
mat:SetTexture( "$basetexture", RenderTarget )
reticle = surface.GetTextureID("sprites/scope_leo")
end
if ( CLIENT ) then
local old = render.GetRenderTarget( )
local ply = LocalPlayer()
CamData = {}
CamData.angles = ply:GetAimVector():Angle()
CamData.origin = ply:GetShootPos()
CamData.x = 0
CamData.y = 0
CamData.w = 1020
CamData.h = 1020
CamData.fov = 5
CamData.drawviewmodel = false
CamData.drawhud = false
CamData.ortho = false
CamData.dopostprocess = false
render.SetRenderTarget( RenderTarget )
cam.Start2D()
render.RenderView(CamData)
surface.SetDrawColor(255, 255, 255, 255)
surface.SetTexture(reticle)
surface.DrawTexturedRect(0, 0, 1900, 1070)
cam.End2D()
render.SetRenderTarget( old )
end
end
Sorry, you need to Log In to post a reply to this thread.