Can someone help me with 3D2D text?

I’m trying to place text on doors in DarkRP, but my cam.Start3D2D doesn’t work properly. If I screw it up the code completely, it does this. (I have to restart GMod to fix this)

[IMG_THUMB]http://puu.sh/34tkj/ad3ddc7b3c.jpg[/IMG_THUMB]

Otherwise, it just generally won’t work.

Here’s my current code in cl_init.lua. This code isn’t producing any text anywhere, and isn’t producing that weird graphical effect. I have tried making the door invisible to see if it’s placing wrong, but it’s not.



for k,v in pairs(ents.GetAll()) do
	if v:GetClass() == "prop_door_rotating" then
		table.insert(doors, v)
	end
end
	
for k,v in pairs(doors) do
	if v == nil then continue end
	local TextWidth = surface.GetTextSize("Door Text")
	cam.Start3D2D( v:GetPos(), v:GetAngles(), 1 )
		draw.SimpleText("A door","DarkRPHUD2",0, 0, Color(255,255,255),1,1) 
	cam.End3D2D() 
end


I’m not very good at lua, and can’t find any examples of 3D2D text I can use. The code does not produce any errors in the server or client console.

If anyone can offer a solution I’d be grateful.

What hook are you using to call this?

I’m not… I’m probably completely screwing everything up and/or doing something horribly wrong. It’s being called as soon as cl_init.lua loads.

You must call cam.3D2D in a 3D rendering hook in order it to work. Like PostDrawOpaqueRenderables. You can find rest of there hooks on GMod Wiki.

Thanks. Can you give me an example?



hook.Add( "PreDrawTranslucentRenderables", "lol", function()
    cam.Start3D( EyePos(), EyeAngles() )
    for id, ent in pairs( ents.FindByClass( "prop_door_rotating" ) ) do
        /*use 3d2d cam here*/
    end
    cam.End3D()
end )

Thank you. Will test it in a bit. :v:

[editline]30th May 2013[/editline]

Doesn’t quite do what I want. I want it to display 3D text on all the doors on the map, like how PERP does it.

Edit: It’s ok, I’ve put my code into a hook and it works… now to sort that framerate drop o.o

How would I do that? Like, the further away they are, the less they see?

Does anyone have a solution to this? Sorry to bump.

Hopefully this will guide you into the write path and not just become a copy/pasta.

Note: You might want to change the font as I was using a custom font at the time.

[lua]
function cam_door_test()
for k,v in pairs(ents.GetAll()) do
if v:GetClass() == “prop_door” || v:GetClass() == “prop_door_rotating” then
local angles = v:GetAngles();
local position = v:GetPos();
local offset = angles:Up() + angles:Forward() * -1.2 + angles:Right() * - 31;
local offset2 = angles:Up() + angles:Forward() * 1.2 + angles:Right() * - 15.5;

		angles:RotateAroundAxis(angles:Forward(), 90);
		angles:RotateAroundAxis(angles:Right(), 90);
		angles:RotateAroundAxis(angles:Up(), 0);


		cam.Start3D2D(position + offset, angles, 0.1);
			draw.SimpleText("Door", "cam_door_test_font", 80.5, 46, Color(255, 255, 255, 255), 1, 1);
			draw.SimpleText("Door", "cam_door_test_font", 80.5, 46, Color(255, 255, 255, 255), 1, 1);
		cam.End3D2D();
		
		angles:RotateAroundAxis(angles:Forward(), 0);
		angles:RotateAroundAxis(angles:Right(), 180);
		angles:RotateAroundAxis(angles:Up(), 0);
		
		cam.Start3D2D(position + offset2, angles, 0.1);
			draw.SimpleText("Door", "cam_door_test_font", 80.5, 46, Color(255, 255, 255, 255), 1, 1);
			draw.SimpleText("Door", "cam_door_test_font", 80.5, 46, Color(255, 255, 255, 255), 1, 1);
		cam.End3D2D();
	end
end

end
hook.Add(“PostDrawOpaqueRenderables”, “cam_door_test”, cam_door_test)
[/lua]