Library render

Render library. Screens are 512x512 units. Most functions require that you be in the rendering hook to call, otherwise an error is thrown. +x is right, +y is down

Functions

capturePixels () Dumps the current render target and allows the pixels to be accessed by render.readPixel.
clear (clr) Clears the surface
createFont (font, size, weight, antialias, additive, shadow, outline, blur, blue) Creates a font.
createPoly (verts) Compiles a 2D poly.
createRenderTarget (name) Creates a new render target to draw onto.
cursorPos (ply) Gets a 2D cursor position where ply is aiming.
drawCircle (x, y, r) Draws a circle outline
drawLine (x1, y1, x2, y2) Draws a line
drawPoly (poly) Draws a polygon.
drawRect (x, y, w, h) Draws a rectangle using the current color.
drawRectOutline (x, y, w, h) Draws a rectangle outline using the current color.
drawText (x, y, text, alignment) Draws text.
drawTexturedRect (x, y, w, h) Draws a textured rectangle.
drawTexturedRectRotated (x, y, w, h, rot) Draws a rotated, textured rectangle.
drawTexturedRectUV (x, y, w, h, startU, startV, endU, endV) Draws a textured rectangle with UV coordinates
getDefaultFont () Gets the default font
getScreenInfo () Returns information about the screen, such as dimentions and rotation.
getScreenPos () Returns the screen surface's world position and angle
getTextSize (text) Gets the size of the specified text.
getTextureID (tx) Looks up a texture ID by file name.
popMatrix () Pops a matrix from the matrix stack.
pushMatrix (m) Pushes a matrix onto the matrix stack.
readPixel (x, y) Reads the color of the specified pixel.
selectRenderTarget (name) Selects the render target to draw on.
setColor (clr) Sets the draw color
setFont (font) Sets the font
setRenderTargetTexture (name) Sets the active texture to the render target with the specified name.
setTexture (id) Sets the texture


Functions

render_library.capturePixels ()
Dumps the current render target and allows the pixels to be accessed by render.readPixel.
render_library.clear (clr)
Clears the surface

Parameters:

  • clr: Color type to clear with
render_library.createFont (font, size, weight, antialias, additive, shadow, outline, blur, blue)
Creates a font. Does not require rendering hook

Parameters:

  • font: Base font to use
  • size: Font size
  • weight: Font weight (default: 400)
  • antialias: Antialias font?
  • additive: If true, adds brightness to pixels behind it rather than drawing over them.
  • shadow: Enable drop shadow?
  • outline: Enable outline?
  • blur:
  • blue: Enable blur?

Usage:

    Base font can be one of (keep in mind that these may not exist on all clients if they are not shipped with starfall): 
    - DebugFixed 
    - DebugFixedSmall 
    - DefaultFixedOutline 
    - MenuItem 
    - Default 
    - TabLarge 
    - DefaultBold 
    - DefaultUnderline 
    - DefaultSmall 
    - DefaultSmallDropShadow 
    - DefaultVerySmall 
    - DefaultLarge 
    - UiBold 
    - MenuLarge 
    - ConsoleText 
    - Marlett 
    - Trebuchet18 
    - Trebuchet19 
    - Trebuchet20 
    - Trebuchet22 
    - Trebuchet24 
    - HUDNumber 
    - HUDNumber1 
    - HUDNumber2 
    - HUDNumber3 
    - HUDNumber4 
    - HUDNumber5 
    - HudHintTextLarge 
    - HudHintTextSmall 
    - CenterPrintText 
    - HudSelectionText 
    - DefaultFixed 
    - DefaultFixedDropShadow 
    - CloseCaption_Normal 
    - CloseCaption_Bold 
    - CloseCaption_BoldItalic 
    - TitleFont 
    - TitleFont2 
    - ChatFont 
    - TargetID 
    - TargetIDSmall 
    - HL2MPTypeDeath 
    - BudgetLabel 
    - DejaVu Sans Mono (shipped, monospaced)
render_library.createPoly (verts)
Compiles a 2D poly. This is needed so that poly don't have to be type-checked each frame. Polys can be indexed by a number, in which a copy of the vertex at that spot is returned. They can also be assigned a new vertex at 1 <= i <= #poly+1. And the length of the poly can be taken.

Parameters:

  • verts: Array of verticies to convert.

Return value:

    compiled polygon
render_library.createRenderTarget (name)
Creates a new render target to draw onto. The dimensions will always be 1024x1024

Parameters:

  • name: The name of the render target

Known bug:

    The drawing will be offset by 16 pixels to the left and 16 to the top and the resolution is actually 992x992. So drawing to 16,16 will draw in the top-left corner and 1007,1007 to the bottom-right.
render_library.cursorPos (ply)
Gets a 2D cursor position where ply is aiming.

Parameters:

  • ply: player to get cursor position from

Return values:

  1. x position
  2. y position
render_library.drawCircle (x, y, r)
Draws a circle outline

Parameters:

  • x: Center x coordinate
  • y: Center y coordinate
  • r: Radius
render_library.drawLine (x1, y1, x2, y2)
Draws a line

Parameters:

  • x1: X start coordinate
  • y1: Y start coordinate
  • x2: X end coordinate
  • y2: Y end coordinate
render_library.drawPoly (poly)
Draws a polygon. Takes a compiled/uncompiled poly to draw. Note that if you do use an uncompiled poly, you will use up ops very quickly!

Parameters:

  • poly: Compiled poly or array of vertexes
render_library.drawRect (x, y, w, h)
Draws a rectangle using the current color.

Parameters:

  • x: Top left corner x coordinate
  • y: Top left corner y coordinate
  • w: Width
  • h: Height
render_library.drawRectOutline (x, y, w, h)
Draws a rectangle outline using the current color.

Parameters:

  • x: Top left corner x coordinate
  • y: Top left corner y coordinate
  • w: Width
  • h: Height
render_library.drawText (x, y, text, alignment)
Draws text.

Parameters:

  • x: X coordinate
  • y: Y coordinate
  • text: Text to draw
  • alignment: Text alignment
render_library.drawTexturedRect (x, y, w, h)
Draws a textured rectangle.

Parameters:

  • x: Top left corner x coordinate
  • y: Top left corner y coordinate
  • w: Width
  • h: Height
render_library.drawTexturedRectRotated (x, y, w, h, rot)
Draws a rotated, textured rectangle.

Parameters:

  • x: X coordinate of center of rect
  • y: Y coordinate of center of rect
  • w: Width
  • h: Height
  • rot: Rotation in degrees
render_library.drawTexturedRectUV (x, y, w, h, startU, startV, endU, endV)
Draws a textured rectangle with UV coordinates

Parameters:

  • x: Top left corner x coordinate
  • y: Top left corner y coordinate
  • w: Width
  • h: Height
  • startU: Texture mapping at rectangle origin
  • startV: Texture mapping at rectangle origin
  • endU:
  • endV: Texture mapping at rectangle end
render_library.getDefaultFont ()
Gets the default font

Return value:

    Default font
render_library.getScreenInfo ()
Returns information about the screen, such as dimentions and rotation. Note: this does a table copy so move it out of your draw hook

Return value:

    A table describing the screen.
render_library.getScreenPos ()
Returns the screen surface's world position and angle

Return values:

  1. The screen position
  2. The screen angle
render_library.getTextSize (text)
Gets the size of the specified text. Don't forget to use setFont before calling this function

Parameters:

  • text: Text to get the size of

Return values:

  1. width of the text
  2. height of the text
render_library.getTextureID (tx)
Looks up a texture ID by file name.

Parameters:

  • tx: Texture file path
render_library.popMatrix ()
Pops a matrix from the matrix stack.
render_library.pushMatrix (m)
Pushes a matrix onto the matrix stack.

Parameters:

  • m: The matrix
render_library.readPixel (x, y)
Reads the color of the specified pixel.

Parameters:

  • x: Pixel x-coordinate.
  • y: Pixel y-coordinate.

Return value:

    Color object with ( r, g, b, 255 ) from the specified pixel.
render_library.selectRenderTarget (name)
Selects the render target to draw on. Nil for the visible RT.

Parameters:

  • name: Name of the render target to use
render_library.setColor (clr)
Sets the draw color

Parameters:

  • clr: Color type
render_library.setFont (font)
Sets the font

Parameters:

  • font: The font to use
render_library.setRenderTargetTexture (name)
Sets the active texture to the render target with the specified name. Nil to reset.

Parameters:

  • name: Name of the render target to use
render_library.setTexture (id)
Sets the texture

Parameters:

  • id: Texture id

Valid XHTML 1.0!