• Display 3D text like in GmodTower
    9 replies, posted
I am wondering how Gmod tower displayed 3D text. Or how to display 3D text at all. Help is appreciated.
[code]include('shared.lua') ENT.RenderGroup = RENDERGROUP_TRANSLUCENT local FONT = "GTowerSkyMsg" local SMALLFONT = "GTowerSkyMsgSmall" surface.CreateFont( "Arial", 144, 100, true, false, FONT ) surface.CreateFont( "Arial", 64, 100, true, false, SMALLFONT ) function ENT:Initialize() self:SetModel( self.Model ) self.NegativeX = 0 self.PositiveY = 0 self.TextWidth = 0 self.TextHeight = 0 self.StrText = "" self.IsTheater = false self.TColor = Color(255,255,255,255) self:DrawShadow( false ) end function ENT:Think() local Skin = tonumber( self:GetSkin() ) if Skin != 0 then self:TextChanged( Skin ) self.Think = EmptyFunction end end function ENT:TextChanged( id ) surface.SetFont( FONT ) if !self.Messages[ id ] then return end self.StrText = self.Messages[ id ] if type( self.StrText ) == "table" then self.TColor = self.StrText.Color or Color(255,255,255,255) self.StrText = self.StrText.Name end if self.StrText == "Theatre" then self.StrText = T("Theater") self.IsTheater = true end local w,h = surface.GetTextSize( self.StrText ) self.NegativeX = -w / 2 self.PositiveY = -h self.TextWidth, self.TextHeight = w, h local min = Vector(0, self.NegativeX, 0) local max = Vector(0, -self.NegativeX, h ) self:SetRenderBounds(min, max) if self.IsTheater then self.DrawExtra = self.DrawTheaterVideo end end function ENT:DrawTranslucent() // Aim the screen forward local ang = self.Entity:GetAngles() local pos = self.Entity:GetPos() + ang:Up() * math.sin( CurTime() ) * 2 ang:RotateAroundAxis( ang:Forward(), 90 ) ang:RotateAroundAxis( ang:Right(), 90 ) if (LocalPlayer():EyePos() - pos ):DotProduct( ang:Up() ) < 0 then ang:RotateAroundAxis( ang:Right(), 180 ) end // Start the fun cam.Start3D2D( pos, ang, 0.5 ) surface.SetFont( FONT ) surface.SetTextColor( self.TColor.r, self.TColor.g, self.TColor.b, self.TColor.a ) surface.SetTextPos( self.NegativeX, self.PositiveY ) surface.DrawText( self.StrText ) self:DrawExtra() cam.End3D2D() end function ENT:DrawExtra() end function ENT:DrawTheaterVideo() if GTowerTheater.CurentlyPlaying == 0 then return end local Video = GTowerTheater.VoteData[ GTowerTheater.CurentlyPlaying ] if !Video || !Video.name then return end local Text = Video.name surface.SetFont( SMALLFONT ) local w,h = surface.GetTextSize( Text ) surface.SetTextColor( 255, 255, 255, 255 ) surface.SetTextPos( self.NegativeX + self.TextWidth / 2 - w / 2, self.PositiveY + self.TextHeight + 10 ) surface.DrawText( Text ) end[/code] [code]ENT.Type = "anim" ENT.Base = "base_anim" ENT.Model = "" ENT.Messages = { [1] = "TODO", [2] = {Name = "Gamemode Ports", IginoreTrace = true }, [3] = "Entertainment Plaza", [4] = "Suite Floor", [5] = "Suites 1-5", [6] = "Suites 6-10", [7] = "Arcade", [8] = "Teleporters", [9] = "Dev. HQ", [10] = "Resturant", [11] = "Ball Race", [12] = "Action Genre", [13] = "PVP Battle", [14] = "Stealth - Coming Soon", [15] = "Coming Soon", [16] = "GMT: Adventure", [17] = "Stealth", [18] = "Puzzle: Impossible", [19] = "Tetris", [20] = "Bar", [21] = "Theatre", [22] = "Party Suite", [23] = "The Gallery", [24] = "Twist of the Mind", [25] = "Mini-Golf", [26] = "Monotone", [27] = "Harvest", [28] = "Furniture Store", [29] = "Hat Store", [30] = "Souvenir Store", [31] = "Electronic Store", [32] = "Conquest", [33] = {Name = "Chainsaw Battle!", IginoreTrace = true, Color = Color(255,0,0,255) } } function ENT:PhysicsUpdate() end function ENT:PhysicsCollide(data,phys) end[/code] [code]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( "shared.lua" ) function ENT:Initialize() self:SetModel( self.Model ) self:DrawShadow( false ) self.Text = 1 if self.KVText then if string.len( self.KVText ) < 3 then self.Text = tonumber( self.KVText ) else for k, v in pairs( self.Messages ) do if type( v ) == "table" then if v.Name == self.KVText then self.Text = k end elseif v == self.KVText then self.Text = k end end end end if self.Text == 1 then Msg( "gmt_skymsg: Could not find text id for: '", self.KVText, "'\n") end self:SetSkin( self.Text ) self.KVText = nil timer.Simple( 1.0, self.UpdateDirection, self ) end function ENT:UpdateDirection() if !IsValid( self ) then return end local Tbl = self.Messages[ self.Text ] if type( Tbl ) == "table" then if Tbl.IginoreTrace == false then return end end local EntPos = self:GetPos() local Trace = {} local function SolicQuickTrace( dir ) return util.TraceLine( { start = EntPos, endpos = EntPos + dir, mask = MASK_PLAYERSOLID, filter = self } ) end table.insert( Trace, SolicQuickTrace( Vector(0,-5000,0) ) ) table.insert( Trace, SolicQuickTrace( Vector(0,5000,0) ) ) table.insert( Trace, SolicQuickTrace( Vector(-5000,0,0) ) ) table.insert( Trace, SolicQuickTrace( Vector(5000,0,0) ) ) for _, v in pairs( Trace ) do if v.StartPos:Distance( v.HitPos ) < 64 then self:SetAngles( ( v.HitNormal * -1 ):Angle() ) return end end if Trace[1].Fraction + Trace[2].Fraction > Trace[3].Fraction + Trace[4].Fraction then self:SetAngles( Angle(0,90,0) ) end end function ENT:KeyValue( key, value ) if key == "text" then self.KVText = string.Trim( value ) end end[/code]
Thank you!
I would like to use this as a floating scoreboard type thingy, can you please guide me on how to? Thanks for the dumb rating i guess....
I believe it should be easier doing 3d2d and just drawing a quick surface All the weirdo code shall be skipped, this sucks as an example, it needs more commenting. Also as usual put it in lua tags!
It's funny because 3d2d is easy.
Sorry, you need to Log In to post a reply to this thread.