Skip to content

🖌️ GRAPHICS#

Note

ANTIRUINS uses center coordinate for drawing.

Note

If you use .dtex files but keep a .png with the same name, the engine will load the .png version when uing the PC renderer.

Textures#

ANTIRUINS only supports pow2 sized texture from 8px to 1024px.

You can load .png files, but they takes some time to decompress, a much better alternative are .dtex file generated by pvrtex and texconv.

local TEXTURE = {
  texture   = id,   -- texture ID used by the C engine
  filename  = "",
  w, h      = 0, 0,
  palette   = {     -- if you use paletted texture.
      index   = 0,
      size    = 0,
      colors  = {}
  }
}

function graphics.loadTexture(filename)
Loads a pow2 .png or .dtex image.
Returns a texture.


function graphics.freeTexture(texture)
Frees the texture data.


function graphics.drawTexture(texture, x, y, scaleX, scaleY, angle, uv)
Draws a texture at x-y position.
OPTIONAL : scaleX and scaleY are floats.
OPTIONAL : angle is represented in degree.
OPTIONAL : uv is a table with 4 x 0.0 - 1.0 UV coordinates.


function graphics.setPixel(texture, x, y)
Sets a pixel in a texture. Uses the current drawColor.


function graphics.getPixel(texture, x, y)
Returns the color of a pixel in a texture.


Fonts#

The fonts are loaded as a bitmap font atlas, starting at character 32 (space). There is a Processing sketch included in the tool folder that can help you generate a font atlas. You can also find some other fonts in the default folder.

local FONT = {
  texture = 0,  -- texture ID used by the engine 
  charW   = 0,  -- char width
  size    = 16,
}

function graphics.loadFont(filename, col, row, fontSize)
Loads a pow2 .png or .dtex image. Returns a font.


function graphics.print(text, x, y, center)
Prints text at x-y position.
If center is true, the text is centered.


function graphics.setFontSize(fontSize)
Sets the current font size.


Palettes#

The Dreamcast has an internal palette of 1024 colors. You can take advantage of this by using paletted .dtex files. Paletted texture reduce the memory of texture to 50% (8BPP) or 25% (4BPP) compared to RGB images.

You can read more on Dreamcast texture format here.

local PALETTE = {
  size    = 16,  --16(4BPP) or 256(8BPP) palette size 
  index   = 0,   --the location of the palette (between 1 and 1024), 0 is no palette.
  colors  = {},  --table of {r,g,b,a} values (between 0.0 and 1.0)
}

function graphics.loadPalette(file)
Returns a palette from a .dtex.pal file.


function graphics.setPalette(texture, palette)
Replaces a texture palette with the provided palette.


function graphics.setPaletteColor(palette, colorNum, r, g, b, a)
Sets a single color in a specified palette.
The r argument can be a {r, g, b, a} table.


Colors#

function graphics.setDrawColor(r, g, b, a)
Sets the color (0.0 - 1.0) of future textures, shapes, texts, etc.
You can also use a {r, g, b, a} table.


function graphics.setClearColor(r, g, b, a)
Sets the color (0.0 - 1.0) of the background.
You can also use a {r, g, b, a} table.


Shapes#

function graphics.drawRect(x, y, w, h, mode)
Draws a rectangle.
If mode is “corners”, x and y become top-left coordinates.


function graphics.drawCircle(x, y, radius, segements)
Draws a circle with the specified number of segments.


function graphics.drawLine(x1, y1, x2, y2, width)
Draws a line from x1-y1 to x2-y2 with the specified line width.


Video#

ANTIRUINS supports ROQ video files.

function graphics.playVideo(videoFile, x, y, w, h)
Plays a video file at the specified position and size.