• Cam 3D2D Help
    14 replies, posted
https://files.facepunch.com/forum/upload/480216/290420c4-fb99-45e6-b90c-68d60e0b3915/Untitled.png Basically, I have a box drawn, and then I have text that goes over it, as shown above. I want to be able to make it so my text doesn't go outside the box. I tried using a scissor rectangle, but they sadly do not work with Cam 3D2D. Will I have to use stencils? Is there another solution out there? If I need to use stencils, where can I find out how to use said stencils?
surface.GetTextSize
I know I can do some ghetto font switching stuff, but I want my font to be able to be read from far away, no matter the length of the text. My idea was to make it so the text slowly scrolls to the right and loops, but I don't know how to do that without a scissor rectangle.
Just a quick google search for scrolling text: Scrolling Text Is this what you're wanting to do?
Yeah, but I want it to be restricted to the boundaries of a box, as shown in the picture I attached.
Would you mind posting the snippet of code with the box and the text that's supposed to be inside of it? Maybe I'm misunderstanding the text bit but perhaps you could use Panel/SizeToContents in this situation. Or as CupCakeR "suggested" you could set the font Width to be a few pixels from the edge of the box you've drawn - combine that with the text equation from google... you might be on the right track.
function ENT:Draw() cam.Start3D2D(self:GetPos()+Vector(0,0,0)+18*arright,self:GetAngles()+Angle(0,0,90), .01) draw.RoundedBox(0,-1000,-1000,2000,250, Color(255,255,255,255)) cam.End3D2D() cam.Start3D2D(self:GetPos()+Vector(0,0,0)+18*arright,self:GetAngles()+Angle(0,0,90), .02) surface.SetFont(FONT) surface.SetTextColor(Color(255,255,255,255)) surface.SetTextPos(-500,-490) surface.DrawText(TEXT) cam.End3D2D() The text has to remain the same size no matter its length. I want to know how to be able to restrict it to just the box. Is it possible to use stencils for this for cam3d2d? If so, where can I find out how to use the stencils?
I think you might be overthinking it - the width in this case, I believe, simply restricts how far the text extends it doesn't actually squish or stretch the text itself, it simply restricts the boundary of the text. I believe it works like Panel/SetSize for DLabel If you post the font and text I can test it out for you and let you know if it works for what you're trying to do.
ADega Serif Regular.otf surface.CreateFont( "Ariallarge", { font = "Adega Serif",  extended = false, size = 500, weight = 500, blursize = 0, scanlines = 0, antialias = true, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = false, additive = false, outline = false, } )
What is arright ?
local arright = self:GetAngles():Right() sorry about that
There any resources out there to teach me how to use stencils?
I've mostly figured it out. Since I basically copied this from another post, I really don't understand stencils, but they worked very well in this application. What I am still having trouble with is, the text has to be drawn on something that is actually drawn, so you can't have it bound by a transparent rectangle, so far as I know. render.ClearStencil() render.SetStencilEnable(true) render.SetStencilWriteMask(255) render.SetStencilTestMask(255) render.SetStencilReferenceValue(10) render.SetStencilFailOperation(STENCILOPERATION_KEEP) render.SetStencilZFailOperation(STENCILOPERATION_KEEP) render.SetStencilPassOperation(STENCILOPERATION_REPLACE) render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_ALWAYS) cam.Start3D2D(self:GetPos()+Vector(0,0,0)+18*arright,self:GetAngles()+Angle(0,0,90), .02) draw.RoundedBox(0,-495,-500,990,125, Color(100,100,100,255)) cam.End3D2D() render.SetStencilCompareFunction(STENCILCOMPARISONFUNCTION_EQUAL) cam.Start3D2D(self:GetPos()+Vector(0,0,0)+18*arright,self:GetAngles()+Angle(0,0,90), .02) surface.SetFont("Ariallarge") surface.SetTextColor(Color(255,255,255,255)) surface.SetTextPos(-500,-490) surface.DrawText(TEXT) cam.End3D2D() render.SetStencilEnable(false)
remember to clear the stencil at the very end as well(Getting a stencil model to render between two conditions) . I don't have any experience with stencils either (I saw you in the thread I made attempting a work around for your issue, so hello!) but why don't you try rendering the stencil after the first cam.End3d2d() I believe the text is its own surface so you should, in theory, be able to use the stencil on it - but again this is mostly speculation.
Very helpful. Thank you.
Sorry, you need to Log In to post a reply to this thread.