DrawText() issue

Hello there!
For some reason, if you hit certain amount of lines for DrawText() function, the rest of the text tends to be broken. As you can see on the screenshot below, some last lines go straight to the upper left corner of my screen.

Function I use for printing 3D text:

function Draw3DTextTT(x,y,z,textInput,colour,fontId,scaleX,scaleY)
    local px,py,pz=table.unpack(GetGameplayCamCoords())
    local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)
    local scale = (1/dist)*20
    local fov = (1/GetGameplayCamFov())*100
    local scale = scale*fov

    SetTextScale(scaleX*scale, scaleY*scale)
    SetTextFont(fontId)
    SetTextProportional(1)
    local colourr,colourg,colourb,coloura = table.unpack(colour)
    SetTextColour(colourr,colourg,colourb, coloura)
    SetTextDropshadow(2, 1, 1, 1, 255)
    SetTextEdge(3, 0, 0, 0, 150)
    SetTextDropShadow()
    SetTextOutline()
    SetTextEntry("STRING")
    SetTextCentre(1)
    AddTextComponentString(textInput)
    SetDrawOrigin(x,y,z+2, 0)
    DrawText(0.0, 0.0)
    ClearDrawOrigin()
end

So each component is drawn separately by calling this function in for a, b in pairs(something) do loop. Is there any solution to this issue? Thanks in advance :slightly_smiling_face:

hello there.

i’m not sure if i understand this, but i’ll try to help you.
are you checking if the text should be on screen, with the GetScreenCoordFromWorldCoord native, and only rendering it when it is?
also, have tried optimising in a way, that the text only renders, if you are in a defined range of it?

Yes, there are limits to how many DrawText calls you can have before they stop rendering in. I am not sure how many it actually is though. I remember that at ~500 I definitely had the issue while trying out a lot of text for my UI resource to look for limits, so maybe 256?

But here you are running into that problem that the text might be “offscreen” and if you still try to render it, it will be in the corner. Basically as @lathlaszlo already said.

I actually remember having a very similar racing script like 5-6 years ago with a list like that. And if you look down so the text shouldn’t be on the screen, it would plop up in the corner as well.

1 Like

Hey! Thanks for your reply.
How to use first native correctly? As for the second - yes.

the native GetScreenCoordFromWorldCoord has 3 arguments.
x, y, and z coordinates. it returns a boolean if it’s on screen, and x, y position on the screen.

get the offscreen value if it’s false then return the function.
hope i could help - lath

1 Like

Thanks man! Your advice with this native actually helped! Apparently, it was rendering labels and stuff for each track and that’s why I hit the limit.

For ppl with the same issue, this is how function should look like (basically just added “if” check):

function Draw3DTextTT(x,y,z,textInput,colour,fontId,scaleX,scaleY)
    local px,py,pz=table.unpack(GetGameplayCamCoords())
    local dist = GetDistanceBetweenCoords(px,py,pz, x,y,z, 1)
    local scale = (1/dist)*20
    local fov = (1/GetGameplayCamFov())*100
    local scale = scale*fov
	if GetScreenCoordFromWorldCoord(x, y, z) then
		SetTextScale(scaleX*scale, scaleY*scale)
		SetTextFont(fontId)
		SetTextProportional(1)
		local colourr,colourg,colourb,coloura = table.unpack(colour)
		SetTextColour(colourr,colourg,colourb, coloura)
		SetTextDropshadow(2, 1, 1, 1, 255)
		SetTextEdge(3, 0, 0, 0, 150)
		SetTextDropShadow()
		SetTextOutline()
		SetTextEntry("STRING")
		SetTextCentre(1)
		AddTextComponentString(textInput)
		SetDrawOrigin(x,y,z+2, 0)
		DrawText(0.0, 0.0)
		ClearDrawOrigin()
	end
end

really happy to help you!
have a nice day!