Help flipping render target

I’ve been trying at this for hours and have not come to a solution. What I’m trying to do is flip the output of the Render Target so that it is not flipped horizontally as seen below. If anyone is able to help that would be fantastic!



SWEP.RTCode = function(self, rt, scrw, scrh)
    if not self:VMIV() then return end


    local vm = self.OwnerViewModel


    if not self.LastOwnerPos then
        self.LastOwnerPos = self.Owner:GetShootPos()
    end


    local owoff = self.Owner:GetShootPos() - self.LastOwnerPos
    self.LastOwnerPos = self.Owner:GetShootPos()
    local pos = vm:GetBonePosition( vm:LookupBone("RT") )
    if not pos then return end
    local scrpos = pos:ToScreen()
    scrpos.x = scrpos.x - scrw / 2 + self.ScopeOverlayTransforms[1]
    scrpos.y = scrpos.y - scrh / 2 + self.ScopeOverlayTransforms[2]
    scrpos.x = math.Clamp(scrpos.x, -1024, 1024)
    scrpos.y = math.Clamp(scrpos.y, -1024, 1024)
    scrpos.x = scrpos.x * self.ScopeOverlayTransformMultiplier
    scrpos.y = scrpos.y * self.ScopeOverlayTransformMultiplier


    if not self.scrpos then
        self.scrpos = scrpos
    end


    self.scrpos.x = math.Approach(self.scrpos.x, scrpos.x, (scrpos.x - self.scrpos.x) * FrameTime() * 10)
    self.scrpos.y = math.Approach(self.scrpos.y, scrpos.y, (scrpos.y - self.scrpos.y) * FrameTime() * 10)
    scrpos = self.scrpos
    render.OverrideAlphaWriteEnable(true, true)
    surface.SetDrawColor(color_white)
    surface.DrawRect(-512, -512, 1024, 1024)
    render.OverrideAlphaWriteEnable(true, true)
    local ang = EyeAngles()
    local AngPos = vm:GetBonePosition( vm:LookupBone("RT") )


    if AngPos then


        if flipcv:GetBool() then
            ang.y = -ang.y
        end


        ang:RotateAroundAxis(ang:Right(), 0)
        ang:RotateAroundAxis(ang:Up(), 0)
        ang:RotateAroundAxis(ang:Forward(), 0)
    end


    cd.angles = ang
    cd.origin = self.Owner:GetShootPos()


    if not self.RTScopeOffset then
        self.RTScopeOffset = {0, 0}
    end


    if not self.RTScopeScale then
        self.RTScopeScale = {1, 1}
    end


    local rtow, rtoh = self.RTScopeOffset[1], self.RTScopeOffset[2]
    local rtw, rth = 512 * self.RTScopeScale[1], 512 * self.RTScopeScale[2]
    cd.x = 0
    cd.y = 0
    cd.w = rtw
    cd.h = rth
    cd.fov = self.RTScopeFOV
    cd.drawviewmodel = false
    cd.drawhud = false
    render.Clear(0, 0, 0, 255, true, true)
    render.SetScissorRect(0 + rtow, 0 + rtoh, rtw + rtow, rth + rtoh, true)


    if self.Scoped_3D then
        render.RenderView(cd)
    end


    render.SetScissorRect(0, 0, rtw, rth, false)
    render.OverrideAlphaWriteEnable(false, true)
    cam.Start2D()
    draw.NoTexture()


    if self.ScopeReticule_CrossCol then
        crosscol.r = cv_cc_r:GetFloat()
        crosscol.g = cv_cc_g:GetFloat()
        crosscol.b = cv_cc_b:GetFloat()
        crosscol.a = cv_cc_a:GetFloat()
        surface.SetDrawColor(crosscol)
    end


    surface.SetMaterial(Material( "scope/mk4_crosshair" ))
    local tmpborderw = rtw * (1 - 1) / 2
    local tmpborderh = rth * (1 - 1) / 2
    surface.DrawTexturedRect(rtow + tmpborderw, rtoh + tmpborderh, rtw - tmpborderw, rth - tmpborderh * 2)
    surface.SetDrawColor(color_black)
    draw.NoTexture()


    surface.SetDrawColor(ColorAlpha(color_black, 255 - 255 * (math.Clamp(self.IronSightsProgress - 0.75, 0, 0.25) * 4)))
    surface.DrawRect(-1024 + rtow, -1024 + rtoh, 2048, 2048)
    surface.DrawTexturedRectUV(rtow, rtoh, rtw, rth, 2, 0, 0, 2)
    cam.End2D()
end


Use 1, 0 as start UVs and 0, 1 as end UVs, should do the trick.

I’m assuming you meant this?


surface.DrawTexturedRectUV(rtow, rtoh, rtw, rth, 2, 0, 0, 2)

to this?


surface.DrawTexturedRectUV(rtow, rtoh, rtw, rth, 1, 0, 0, 1)

If so that didn’t do anything.

You’re already drawing it with a start UV of 1 and an end of 0 on the x-axis, meaning you’re drawing it from 1 back to 0 which is reversed. Simply flip those back around so it becomes 0,0,1,1, or in your case 2 if you need it.