PixelMap
Package: Libraries.Game.Graphics · Inherits from: Libraries.Language.Object, Libraries.Game.Disposable
The PixelMap class represents an image as a collection of individual pixels. It is used by the Texture class to draw shapes and load images from files. This is a class used internally by the game engine, and most users will not need to interface with this class directly.
Actions
CopyChannel(Libraries.Game.Graphics.PixelMap source, integer sourceChannel, integer destinationChannel)
This action copies one channel of another PixelMap of the same size into one channel of this one, pixel by pixel. Channels are 0 red, 1 green, 2 blue and 3 alpha. Both PixelMaps must be in the RGBA8888 format, which all loaded images are when using the Vulkan renderer. Nothing is blended.
Parameters
sourceLibraries.Game.Graphics.PixelMap: The PixelMap to copy from.sourceChannelinteger: The channel to copy, 0 to 3.destinationChannelinteger: The channel to copy into, 0 to 3.
CopyGrayValue(Libraries.Game.Graphics.PixelMap source, integer destinationChannel)
This action copies the gray value of another PixelMap of the same size into one channel of this one. A gray image's value is read from alpha when its red, green and blue are all full (how a one-channel image is loaded), and from red otherwise. Both must be RGBA8888. Nothing is blended.
Parameters
sourceLibraries.Game.Graphics.PixelMap: The gray PixelMap to copy from.destinationChannelinteger: The channel to copy into, 0 to 3.
CreatePixelMap(integer newWidth, integer newHeight, Libraries.Game.Graphics.Format newFormat)
This action will create new PixelMap data to be used in OpenGL with the given width, height, and Format.
Parameters
newWidthintegernewHeightintegernewFormatLibraries.Game.Graphics.Format
Define2DImage(integer target, integer mipLevel, integer border)
This action will create OpenGL information for the currently loaded PixelMap information.
Parameters
targetintegermipLevelintegerborderinteger
Dispose()
This action will free up the memory used to store the pixel information of the image. This should only be used when the PixelMap is no longer needed.
DisposeAfterTextureLoad()
This action returns whether or not this PixelMap should be automatically disposed of after being loaded into a Texture. Disposing of the PixelMap frees up the memory it stores, but makes it unusable without loading it again. By default, this value is true. If this value is false, the user must manually call Dispose on the PixelMap when it is no longer needed.
Returns
boolean
DrawCircle(integer x, integer y, integer radius, integer color)
This action will draw a hollow circle at the given point with the given radius using the given color code.
Parameters
xintegeryintegerradiusintegercolorinteger
DrawCircle(integer x, integer y, integer radius, Libraries.Game.Graphics.Color color)
This action will draw a hollow circle at the given point with the given radius using the given color.
Parameters
xintegeryintegerradiusintegercolorLibraries.Game.Graphics.Color
DrawLine(integer x1, integer y1, integer x2, integer y2, Libraries.Game.Graphics.Color color)
This action will draw a line on the PixelMap between the two points given using the given color.
Parameters
x1integery1integerx2integery2integercolorLibraries.Game.Graphics.Color
DrawLine(integer x1, integer y1, integer x2, integer y2, integer color)
This action will draw a line on the PixelMap between the two points given using the given color code.
Parameters
x1integery1integerx2integery2integercolorinteger
DrawPixelMap(Libraries.Game.Graphics.PixelMap pixmap, integer x, integer y)
This action takes a different PixelMap and draws it on top of this PixelMap at the given x,y coordinates on this PixelMap.
Parameters
pixmapLibraries.Game.Graphics.PixelMapxintegeryinteger
DrawPixelMap(Libraries.Game.Graphics.PixelMap pixmap, integer sourceX, integer sourceY, integer destX, integer destY, integer sourceWidth, integer sourceHeight)
This action will draw a different PixelMap starting from the destX and destY with sourceWidth and sourceHeight on top of this PixelMap at the coordinates of sourceX, sourceY.
Parameters
pixmapLibraries.Game.Graphics.PixelMapsourceXintegersourceYintegerdestXintegerdestYintegersourceWidthintegersourceHeightinteger
DrawRectangle(integer x, integer y, integer width, integer height, Libraries.Game.Graphics.Color color)
This action will draw a hollow rectangle at the given point with the given width and height using the given color.
Parameters
xintegeryintegerwidthintegerheightintegercolorLibraries.Game.Graphics.Color
DrawRectangle(integer x, integer y, integer width, integer height, integer color)
This action will draw a hollow rectangle at the given point with the given width and height using the given color code.
Parameters
xintegeryintegerwidthintegerheightintegercolorinteger
Fill(Libraries.Game.Graphics.Color color)
This action will fill the complete bitmap with the given color.
Parameters
Fill(integer color)
This action will fill the complete bitmap with the given color code.
Parameters
colorinteger
FillCircle(integer x, integer y, integer radius, integer color)
This action will draw a solid circle at the given point with the given radius using the given color code.
Parameters
xintegeryintegerradiusintegercolorinteger
FillCircle(integer x, integer y, integer radius, Libraries.Game.Graphics.Color color)
This action will draw a solid circle at the given point with the given radius using the given color.
Parameters
xintegeryintegerradiusintegercolorLibraries.Game.Graphics.Color
FillRectangle(integer x, integer y, integer width, integer height, Libraries.Game.Graphics.Color color)
This action will draw a solid rectangle at the given point with the given width and height using the given color.
Parameters
xintegeryintegerwidthintegerheightintegercolorLibraries.Game.Graphics.Color
FillRectangle(integer x, integer y, integer width, integer height, integer color)
This action will draw a solid rectangle at the given point with the given width and height using the given color code.
Parameters
xintegeryintegerwidthintegerheightintegercolorinteger
FillTriangle(integer x1, integer y1, integer x2, integer y2, integer x3, integer y3, Libraries.Game.Graphics.Color color)
This action will draw a solid triangle using the three given points and the given color.
Parameters
x1integery1integerx2integery2integerx3integery3integercolorLibraries.Game.Graphics.Color
FillTriangle(integer x1, integer y1, integer x2, integer y2, integer x3, integer y3, integer color)
This action will draw a solid triangle using the three given points and the given color.
Parameters
x1integery1integerx2integery2integerx3integery3integercolorinteger
GetBlending()
This action will return the Blending being used on this PixelMap.
Returns
GetColor()
Returns the color being applied to this PixelMap.
Returns
GetFormat()
Returns the Format that is used by this PixelMap.
Returns
GetGLInternalFormat()
This action returns an integer value representing the internal GL format.
Returns
integer
GetHeight()
Returns the height of this PixelMap.
Returns
integer
GetPixel(integer x, integer y)
This action will return an integer color code representing the color of the pixel at the given coordinates.
Parameters
xintegeryinteger
Returns
integer
GetWidth()
Returns the width of this PixelMap.
Returns
integer
InvertChannel(integer channel)
This action replaces one channel of every pixel with 255 minus its value, such as to turn a DirectX normal map into an OpenGL one by inverting green. This PixelMap must be RGBA8888.
Parameters
channelinteger: The channel to invert, 0 to 3.
LoadAsynchronously(Libraries.System.File file, Libraries.Game.Graphics.Format format, boolean useMipMaps, Libraries.Game.Graphics.Drawable drawable, Libraries.Game.Graphics.Texture texture)
This action will asynchronously load the PixelMap (that is, it will be loaded separately from the rest of the program's execution) and then it will be loaded into the provided Texture, which will be used to load the provided Drawable (if it is not undefined). This is only needed for use on the web, and when loading Drawables or Textures directly via files or file paths, it is called automatically. Most users will never need to use this action directly.
Parameters
fileLibraries.System.File: The image file to load the pixels from.formatLibraries.Game.Graphics.Format: The pixel format to be used for retrieving and storing the pixels.useMipMapsboolean: Whether or not the generated Texture using this PixelMap should generate mip maps.drawableLibraries.Game.Graphics.Drawable: The Drawable to be loaded using this PixelMap/Texture, if not undefined.textureLibraries.Game.Graphics.Texture: The Texture to be loaded using this PixelMap.
LoadMatrix(Libraries.Compute.Matrix matrix)
This action will load a matrix into the PixelMap to create a monochrome (black and white) image. Each value is assumed to be between 0 and 1, where 0 represents a black pixel and 1 represents a white pixel.
Parameters
matrixLibraries.Compute.Matrix: The matrix representing the pixels to load.
Example
use Libraries.Game.Game
use Libraries.Game.Graphics.PixelMap
use Libraries.Game.Graphics.Drawable
use Libraries.Game.Graphics.Texture
use Libraries.Compute.Matrix
class Main is Game
PixelMap pixelMap
Texture texture
Drawable drawable
action Main
StartGame()
end
action CreateGame
Matrix matrix
// 7x7 square that is black at edges and lightens as it goes towards the center.
matrix:Fill(7, 7, 0)
matrix:Set(1, 1, 0.33)
matrix:Set(2, 1, 0.33)
matrix:Set(3, 1, 0.33)
matrix:Set(4, 1, 0.33)
matrix:Set(5, 1, 0.33)
matrix:Set(5, 2, 0.33)
matrix:Set(5, 3, 0.33)
matrix:Set(5, 4, 0.33)
matrix:Set(5, 5, 0.33)
matrix:Set(4, 5, 0.33)
matrix:Set(3, 5, 0.33)
matrix:Set(2, 5, 0.33)
matrix:Set(1, 5, 0.33)
matrix:Set(1, 4, 0.33)
matrix:Set(1, 3, 0.33)
matrix:Set(1, 2, 0.33)
matrix:Set(2, 2, 0.66)
matrix:Set(3, 2, 0.66)
matrix:Set(4, 2, 0.66)
matrix:Set(4, 3, 0.66)
matrix:Set(4, 4, 0.66)
matrix:Set(3, 4, 0.66)
matrix:Set(2, 4, 0.66)
matrix:Set(2, 3, 0.66)
matrix:Set(3, 3, 1)
pixelMap:LoadMatrix(matrix)
// Loading the PixelMap and blowing up the size of the Drawable to make it easier to see.
texture:LoadFromPixelMap(pixelMap)
drawable:Load(texture)
Add(drawable)
drawable:SetPosition(200, 200)
drawable:SetSize(100, 100)
end
end
LoadPixelMap(Libraries.System.File file)
This action will load a PixelMap using an image file.
Parameters
Save(Libraries.System.File file)
This action writes a PixelMap to disk in either png, jpg, jpeg, gif, bmp, or dib format. This action works only on Desktop platforms.
Parameters
ScaleNormalsByOcclusion(Libraries.Game.Graphics.PixelMap occlusion)
This action treats this PixelMap as a normal map and folds an ambient occlusion map into it, Terrain3D's way: each normal is made unit length and then scaled by the square root of the occlusion times one half, plus one half. A shader reads the occlusion back as twice the normal's length minus one, and the direction by normalizing. Only red, green and blue change. Both must be RGBA8888 and the same size.
Parameters
occlusionLibraries.Game.Graphics.PixelMap: The gray ambient occlusion PixelMap.
Screenshot(integer x, integer y, integer width, integer height)
This action takes a screenshot of the Game window at the given coordinates and stores it in this PixelMap. Taking screenshots is very timing sensitive and can be unreliable on some platforms (especially the web) if done at the wrong time. It's recommended to use the Game's "Screenshot" action and a ScreenshotListener to reliably take screenshots, instead of using this action.
Parameters
xintegeryintegerwidthintegerheightinteger
Screenshot()
This action takes a screenshot of the Game window and loads it into this PixelMap. Taking screenshots is very timing sensitive and can be unreliable on some platforms (especially the web) if done at the wrong time. It's recommended to use the Game's "Screenshot" action and a ScreenshotListener to reliably take screenshots, instead of using this action.
SetBlending(Libraries.Game.Graphics.Blending newBlend)
This action will set the Blending to be used for this PixelMap.
Parameters
newBlendLibraries.Game.Graphics.Blending
SetChannel(integer channel, integer value)
This action sets one channel of every pixel to the same value. This PixelMap must be RGBA8888. Nothing is blended.
Parameters
channelinteger: The channel to set, 0 to 3.valueinteger: The value, 0 to 255.
SetColor(Libraries.Game.Graphics.Color newColor)
Sets the color being used by this PixelMap using a Color object.
Parameters
newColorLibraries.Game.Graphics.Color
SetColor(number redValue, number greenValue, number blueValue, number alphaValue)
Sets the color being used by this PixelMap using color component values between 0 and 1 for the red, green, blue, and alpha components.
Parameters
redValuenumbergreenValuenumberblueValuenumberalphaValuenumber
SetColorFromCode(integer code)
Sets the color being used by this PixelMap using an integer color code.
Parameters
codeinteger
SetDisposeAfterTextureLoad(boolean disposeAfterTextureLoad)
This action sets whether or not this PixelMap should be automatically disposed of after being loaded into a Texture. Disposing of the PixelMap frees up the memory it stores, but makes it unusable without loading it again. By default, this value is true. If this value is false, the user must manually call Dispose on the PixelMap when it is no longer needed.
Parameters
disposeAfterTextureLoadboolean
SetFilter(Libraries.Game.Graphics.Filter filter)
Sets the type of interpolation Filter to be used for this PixelMap.
Parameters
SetPixel(integer x, integer y)
This action will set the pixel at the given coordinates with the PixelMap's current color.
Parameters
xintegeryinteger
SetPixel(integer x, integer y, integer code)
This action will set the pixel at the given coordinates with the given color code.
Parameters
xintegeryintegercodeinteger
SetPixel(integer x, integer y, Libraries.Game.Graphics.Color setColor)
This action will set the pixel at the given coordinates with the given color.
Parameters
xintegeryintegersetColorLibraries.Game.Graphics.Color
SetScale(integer scale)
This action will set the scaling filter to the given type.
Parameters
scaleinteger