Garry's Mod Wiki

surface

The surface library allows you to draw text and shapes on the screen. Primarily used for making HUDs & custom GUI panels.

Methods

surface.CreateFont( string fontName, table fontData )
Creates a new font. To prevent the font from displaying incorrectly when using the "outline" setting, set "antialias" to false. This will ensure the text properly fills out the entire outline. Be sure to check the List of Default Fonts first! Those fonts can be used without using this function. See Also: Finding the Font Name. Due to the static nature of fonts, do NOT create the font more than once. You should only be creating them once, it is recommended to create them at the top of y..
surface.DisableClipping( boolean disable )
We advise against using this. It may be changed or removed in a future update. Alias of DisableClipping so use that instead. Enables or disables the clipping used by the VGUI that limits the drawing operations to a panels bounds. Identical to DisableClipping. See also Panel:NoClipping.
surface.DrawCircle( number originX, number originY, number radius, number r, number g, number b, number a = 255 )
Draws a hollow circle, made of dots. For a filled circle, see examples for surface.DrawPoly. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
surface.DrawLine( number startX, number startY, number endX, number endY )
Draws a line from one point to another. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
surface.DrawOutlinedRect( number x, number y, number w, number h )
Draws a hollow box with a border width of 1 px. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
surface.DrawPoly( table vertices )
Draws a textured polygon (secretly a triangle fan) with a maximum of 256 vertices. Only works properly with convex polygons. You may try to render concave polygons, but there is no guarantee that things wont get messed up. Unlike most surface library functions, non-integer coordinates are not rounded. You must reset the drawing color and texture before calling the function to ensure consistent results. See examples below.This is a rendering function that requires a 2d rendering context. This means that it..
surface.DrawRect( number x, number y, number width, number height )
Draws a solid rectangle on the screen. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
surface.DrawText( string text )
Draw the specified text on the screen, using the previously set position, font and color. This function does not handle newlines properlyThis function sets new text position at the end of the previous drawn text length - this can be used to change text properties (such as font or color) without recalculating and resetting text position. See example #2 for example use of this behavior.This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
surface.DrawTexturedRect( number x, number y, number width, number height )
Draw a textured rectangle with the given position and dimensions on the screen, using the current active texture set with surface.SetMaterial. It is also affected by surface.SetDrawColor. See also render.SetMaterial and render.DrawScreenQuadEx. See also surface.DrawTexturedRectUV. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
surface.DrawTexturedRectRotated( number x, number y, number width, number height, number rotation )
Draw a textured rotated rectangle with the given position and dimensions and angle on the screen, using the current active texture. This is a rendering function that requires a 2d rendering context. This means that it will only work in 2d Rendering Hooks.
surface.DrawTexturedRectUV( number x, number y, number width, number height, number startU, number startV, number endU, number endV )
Draws a textured rectangle with a repeated or partial texture. u and v refer to texture coordinates. (u, v) = (0, 0) is the top left (u, v) = (1, 0) is the top right (u, v) = (1, 1) is the bottom right (u, v) = (0, 1) is the bottom left Using a start point of (1, 0) and an end point to (0, 1), you can draw an image flipped horizontally, same goes with other directions. Going above 1 will tile the texture. Negative values are allowed as well. Here's a helper image: If you are using a .png image, you need..
number surface.GetAlphaMultiplier()
Returns the current alpha multiplier affecting drawing operations.
table surface.GetDrawColor()
Returns the current color affecting draw operations. The returned color will not have the color metatable.
number surface.GetHUDTexture( string name )
Gets the HUD icon TextureID with the specified name.
table surface.GetTextColor()
Returns the current color affecting text draw operations. The returned color will not have the color metatable.
number, number surface.GetTextSize( string text )
Returns the width and height (in pixels) of the given text, but only if the font has been set with surface.SetFont.
number surface.GetTextureID( string name/path )
Returns the texture id of the material with the given name/path. This function will not work with .png or .jpg images. For that, see Material
number, number surface.GetTextureSize( number textureID )
Returns the size of the texture with the associated texture ID. For .png/.jpg textures loaded with Material you can use the $realheight and $realwidth material parameters (IMaterial:GetInt) to get the size of the image.
surface.PlaySound( string soundfile )
Play a sound file directly on the client (such as UI sounds, etc).
number surface.ScreenHeight()
We advise against using this. It may be changed or removed in a future update. You should use ScrH instead. Returns the height of the current client's screen.
number surface.ScreenWidth()
We advise against using this. It may be changed or removed in a future update. You should use ScrW instead. Returns the width of the current client's screen.
surface.SetAlphaMultiplier( number multiplier )
Sets the alpha multiplier that will influence all upcoming drawing operations. See also render.SetBlend.
surface.SetDrawColor( number r, number g, number b, number a = 255 )
Set the color of any future shapes to be drawn, can be set by either using R, G, B, A as separate values or by a Color. Using a color structure is not recommended to be created procedurally. Providing a Color structure is slower than providing four numbers. You may use Color:Unpack for this.The alpha value may not work properly if you're using a material without $vertexalpha.
surface.SetFont( string fontName )
Set the current font to be used for text operations later. The fonts must first be created with surface.CreateFont or be one of the Default Fonts.
surface.SetMaterial( IMaterial material )
Sets the material to be used in all upcoming draw operations using the surface library. Not to be confused with render.SetMaterial. See also surface.SetTexture. If you need to unset the texture, use the draw.NoTexture convenience function. Material function calls are expensive to be done inside this function or inside rendering context, you should be caching the results of Material callsWhen using render.PushRenderTarget or render.SetRenderTarget, material should have the $ignorez flag set to make it visi..
surface.SetTextColor( number r, number g, number b, number a = 255 )
Set the color of any future text to be drawn, can be set by either using R, G, B, A as separate numbers or by a Color. Using a color structure is not recommended to be created procedurally. Providing a Color structure is slower than providing four numbers. You may use Color:Unpack for this.
surface.SetTextPos( number x, number y )
Set the top-left position to draw any future text at.
surface.SetTexture( number textureID )
Sets the texture to be used in all upcoming draw operations using the surface library. See also surface.SetMaterial for an IMaterial alternative.

Page Links


Special Pages


Wikis

?

Render Time: 24ms

DB GetPage 5
Generate Html 2
SaveChanges (1) 9
Render Body 0
Render Sidebar 6