Cam 3D2D trouble.

I’m having a little hard time understanding how 3D2D works. I’m trying to draw text at world positions, and the way I understand it I should use cam.Start3D2D(worldpos, angle-of-2D-surface, scale-of-2D-surface), and then just use draw.DrawText, and that which X/Y coordinates I use there make absolutely no difference (though I’m probably wrong about that). Could someone explain what I’m misunderstanding? Because when I do this, I can’t see text -anywhere-.

Post the code you are using.


local function DrawText()
local color = Color( 0, 0, 0, 0 ) – Black text
local selfpos = LocalPlayer():GetShootPos() – Player’s face

for ID, texttbl in pairs(chattbl) do
	local ent = ents.GetByIndex(ID)
	if ent and ent:IsValid() then
		local pos = ent:GetPos() + Vector(0, 0, ent:OBBMaxs().z)	-- Above entity
		local ang = (pos - selfpos):GetNormal():Angle()			-- Facing player's face
		for i, tbl in ipairs(texttbl) do
			color.a = math.Clamp(tbl[2] * 25, 0, 255)		-- tbl[2] is the time (in tenths of a second) that text will be shown; It's lowered in a function hooked to think. This should make it fade out during the last second.
			cam.Start3D2D(pos + Vector(0,0,i * 10), ang, 10)	-- Draw 2D elements at position in 3D world? *shrug* Also, draw it further above the position if there are several texts to show. 
				draw.DrawText( tbl[1], "Default", 0, 0, color, TEXT_ALIGN_CENTER )
		chattbl[ID] = nil

for _, tbl in ipairs(texttbl) do
	local pos = selfpos + tbl[2]			-- Basicly, this is text shown to be originating from a direction. tbl[2] is a normalized vector pointing at the direction the text came from. 
	color.a = math.Clamp(tbl[3] * 25, 0, 255)	-- tbl[3] is the time it's shown in this case.
	cam.Start3D2D( pos, (pos - selfpos):GetNormal():Angle(), 10)
		draw.DrawText( tbl[1], "Default", 0, 0, color, TEXT_ALIGN_CENTER )

hook.Add(“PostDrawOpaqueRenderables”, “AdvHear_DrawText”, DrawText)[/lua]

EDIT: Just made some changes to the code. Added comments too. I’m probably gonna have to change the angles but I should at least be able to see the text, right?


I just tried changing the text so it’s white, and now when I use a command to print text where the player’s looking, I notice white pixels forming a skewed line. The line seems to start in the general direction I printed the text, and end about 180 degrees to the right. It’s tilted however and doesn’t start exactly where I printed the text.

EDIT: Lowering the scale made the line considerably shorter. Is it printing outside the surface? Is that even possible?

You didn’t translate the angle properly, look at the gmod wiki page on cam.Start3d2d about that.


Well, it works. Thanks for your help :slight_smile: