This is the component provided by graphics cards. For simple programs the term API will usually all you need. For more complex operations, or to get a bit more performance, you may wish to interact with the GPU directly, though.
As of OC 1.3 screens of tier 2 and 3 have a 16 color palette. The palette is used to determine the exact colors used when displaying an RGB color.
For tier two this palette contains all colors the screen can possibly display, and is initialized to the standard Minecraft colors. As a side-effect you can specify the colors using
gpu.setBackground(colors.red, true), for example. Keep in mind this only works on tier two screens.
Tier three also has an editable 16 color palette, and also a 240 color fixed palette. The editable palette is initialized to grayscale values. The remaining 240 colors are stored as truncated RGB values as was the case in older versions of OpenComputers.
bind(address: string[, reset: boolean=true]): boolean[, string]
falseand an error message on failure. Resets the screen's settings if reset is 'true'. A GPU can only be bound to one screen at a time. All operations on it will work on the bound screen. If you wish to control multiple screens at once, you'll need to put more than one graphics card into your computer.
getBackground(): number, boolean
0xRRGGBB, or a palette index. The second returned value indicates which of the two it is (
truefor palette color,
falsefor RGB value).
setBackground(color: number[, isPaletteIndex: boolean]): number[, index]
nil. Note that the color is expected to be specified in hexadecimal RGB format, i.e.
0xRRGGBB. This is to allow uniform color operations regardless of the color depth supported by the screen and GPU.
getForeground(): number, boolean
getBackground, but for the foreground color.
setForeground(color: number[, isPaletteIndex: boolean]): number[, index]
setBackground, but for the foreground color.
getPaletteColor(index: number): number
setPaletteColor(index: number, value: number): number
setDepth(bit: number): boolean
trueif the depth was set,
maxResolution(): number, number
getResolution(): number, number
setResolution(width: number, height: number): boolean
trueif the resolution was set,
getSize(): number, number
get(x: number, y: number): string, number, number, number or nil, number or nil
set(x: number, y: number, value: string[, vertical:boolean]): boolean
trueif the string was set to the buffer,
copy(x: number, y: number, width: number, height: number, tx: number, ty: number): boolean
heightparameters. The target rectangle is defined by
x + tx,
y + ty,
fill(x: number, y: number, width: number, height: number, char: string): boolean
ycoordinates and the rectangle's
height. The fill character
charmust be a string of length one, i.e. a single character. Returns
) is usually less expensive, i.e. consumes less energy, because it is considered a “clear” operation (see config).
local component = require("component") local gpu = component.gpu -- get primary gpu component local w, h = gpu.getResolution() gpu.fill(1, 1, w, h, " ") -- clears the screen gpu.setForeground(0x000000) gpu.setBackground(0xFFFFFF) gpu.fill(1, 1, w/2, h/2, "X") -- fill top left quarter of screen gpu.copy(1, 1, w/2, h/2, w/2, h/2) -- copy top left quarter of screen to lower right
Color Depth (see
gpu.getDepth) can be 1, 4, or 8 bits separately for foreground and background. These depths provide 2, 16, and 256 colors respectively.
The color value (the
number passed to
gpu.setForeground) is interpreted either as a 8 bits per channel rgb value (24 bit color) or a palette index.
The background and foreground colors, as set by calling
setForeground, are defined by a
value (number) and
is_palette (boolean) pair (the boolean being optional).
is_palette is false (or
value is interpreted as a 24 bit rgb color (0xRRGGBB), regardless of depth. However, the color is approximated to the closest available color in the given depth. In monochrome, zero rounds to zero and all nonzero values round to 1 (and the configured monochrome color is used). In 4 bit color, the closest available color in the palette is selected. In 8 bit color the closest color of the available 256 colors is used. The available 256 colors are described in the following table:
Image by Eunomiac
value is interpreted as palette index [0, 16). If you switch from a higher bit density to monochrome note that the color value from the palette is used to determine zero vs the nonzero monochrome color. It is an error to specify a paletted color (i.e. an index value and
true) in 1 bit depth.
Note that the original color pair (the value
number and palette
bool) are preserved (background and foreground each) even when switching bit depths. The actual rendering on the screen will update to respect the new depth, but the original 24bit rgb value (or palette index) is not lost. For example, calling
gpu.getBackground while in 1 bit mode will return the original 24 bit rgb value specified from any previous color depth.
|Components||3D Printer - Abstract Bus - Access Point - Chunkloader - Computer - Crafting - Data Card - Database - Debug - Drone - Drive - EEPROM - Experience - Filesystem - Generator - Geolyzer - GPU - Hologram - Internet - Inventory Controller - Leash - Modem - Motion Sensor - Navigation - Piston Redstone - Robot - Screen - Sign - Tank Controller - Tractor Beam - Transposer - - Tunnel - World Sensor|
|Others||Component Access - Signals|