Team Spartan Cookies & Milk Forums
render.drawBeam() and textures - Printable Version

+- Team Spartan Cookies & Milk Forums (https://teamscm.co.uk)
+-- Forum: Garry's Mod (https://teamscm.co.uk/forum-4.html)
+--- Forum: Starfall (https://teamscm.co.uk/forum-7.html)
+--- Thread: render.drawBeam() and textures (/thread-3429.html)



render.drawBeam() and textures - The17thDoctor - 22-08-2020

When drawing any textured element ( either Wireframe Box or Textured Rect ) the beam takes the last registered texture. But if nothing is drawn and we just use render.setTexture(),
the beam isnt affected at all.
Perhaps could drawBeam() be used alongside setTexture() without having to do some hacky rectangle drawing ?

Example of code :
--@name
--@author

Keeper_Beam = render.getTextureID("tscm/beam_keeper2.png")

hook("render", "draw it nao", function()
local plys = find.allPlayers()
render.clear()
render.setColor(255,255,255)
render.setTexture(Keeper_Beam)
render.drawTexturedRect(0,0,100,100) --Comment me !

render.start3D()
for i = 1,#plys do
local ply = plys[i]
render.drawBeam(ents.self():pos(), ply:pos(), 2, 1, 0,Color(255,255,255))
end
render.end3D()
end)



RE: render.drawBeam() and textures - Person8880 - 23-08-2020

3D operations take their material from calls to render.setMaterial(), which requires a Material instance. I'm guessing that the engine is setting the 3D material somewhere inside the textured rectangle draw which is why you see it ending up on the beam.

There was a bug in the material validation in render.setMaterial() that was making it reject PNGs and other materials which will be fixed after the next restart. Here's how I changed your code to work properly:
Keeper_Beam = Material("tscm/beam_keeper2.png")

hook("render", "draw it nao", function()
local plys = find.allPlayers()
render.clear()
render.setColor(255,255,255)
-- Set the 2D rendering material.
render.setTexture(Keeper_Beam)
render.drawTexturedRect(0,0,100,100)

render.start3D()
-- Set the 3D rendering material.
render.setMaterial(Keeper_Beam)
for i = 1,#plys do
local ply = plys[i]
render.drawBeam(ents.self():pos(), ply:pos(), 2, 1, 0,Color(255,255,255))
end
render.end3D()
end)



RE: render.drawBeam() and textures - The17thDoctor - 23-08-2020

The rect was purely to apply the material on the beam itself so I dont need it. Thanks though.