Difference between revisions of "love.graphics"
(Inform about the coordinate system being aligned to the topleft corner of the pixels itself, not to their centers.https://bitbucket.org/rude/love/issues/595/inconsistent-rectangle-drawing-among-oses#comment-3814377) |
(Describe radians and rotation) |
||
Line 7: | Line 7: | ||
In many cases, you draw images or shapes in terms of their upper-left corner (See the picture above). | In many cases, you draw images or shapes in terms of their upper-left corner (See the picture above). | ||
− | Many of the functions are used to manipulate the ''graphics coordinate system'', which is essentially the way coordinates are mapped to the display. You can change the position, scale, and even rotation in this way. | + | |
+ | A note about angles in LÖVE: Angles are expressed in terms of [https://en.wikipedia.org/wiki/Radian radians], with values in the range of 0 to 2Π (approximately 6.28); you may be more used to working in terms of degrees. | ||
+ | Because of how the coordinate system is set up, with an origin in the upper left corner, angles in LÖVE may seem a bit backwards: 0 points right (along the X axis), ¼Π points diagonally down and to the right, ½Π points directly down (along the Y axis), with increasing values continuing '''clockwise'''. | ||
+ | |||
+ | |||
+ | Many of the functions are used to manipulate the ''graphics coordinate system'', which is essentially the way coordinates are mapped to the display. You can change the position, scale, and even change rotation in this way. | ||
Revision as of 22:18, 30 May 2018
The primary responsibility for the love.graphics module is the drawing of lines, shapes, text, Images and other Drawable objects onto the screen. Its secondary responsibilities include loading external files (including Images and Fonts) into memory, creating specialized objects (such as ParticleSystems or Canvases) and managing screen geometry.
LÖVE's coordinate system is rooted in the upper-left corner of the screen, which is at location (0, 0). The x axis is horizontal: larger values are further to the right. The y axis is vertical: larger values are further towards the bottom. It is worth noting that the location (0, 0) aligns with the upper-left corner of the pixel as well, meaning that for some functions you may encounter off-by-one problems in the render output when drawing 1 pixel wide lines. You can try aligning the coordinate system with the center of pixels rather than their upper-left corner. Do this by passing x+0.5 and y+0.5 or using love.graphics.translate().
In many cases, you draw images or shapes in terms of their upper-left corner (See the picture above).
A note about angles in LÖVE: Angles are expressed in terms of radians, with values in the range of 0 to 2Π (approximately 6.28); you may be more used to working in terms of degrees.
Because of how the coordinate system is set up, with an origin in the upper left corner, angles in LÖVE may seem a bit backwards: 0 points right (along the X axis), ¼Π points diagonally down and to the right, ½Π points directly down (along the Y axis), with increasing values continuing clockwise.
Many of the functions are used to manipulate the graphics coordinate system, which is essentially the way coordinates are mapped to the display. You can change the position, scale, and even change rotation in this way.
Contents
Types
Canvas | Off-screen render target. | 0.8.0 | |
Drawable | Superclass for all things that can be drawn on screen. | ||
Font | Defines the shape of characters than can be drawn onto the screen. | ||
Framebuffer | Off-screen render target. | 0.7.0 | 0.8.0 |
Image | Drawable image type. | ||
Mesh | A 2D polygon mesh used for drawing arbitrary textured shapes. | 0.9.0 | |
ParticleSystem | Used to create cool effects, like fire. | ||
PixelEffect | Pixel shader effect. | 0.8.0 | 0.9.0 |
Quad | A quadrilateral with texture coordinate information. | ||
Shader | Shader effect. | 0.9.0 | |
SpriteBatch | Store image positions in a buffer, and draw it in one call. | ||
Text | Drawable text. | 0.10.0 | |
Texture | Superclass for drawable objects which represent a texture. | 0.9.1 | |
Video | A drawable video. | 0.10.0 |
Functions
Drawing
love.graphics.arc | Draws an arc. | 0.8.0 | |
love.graphics.circle | Draws a circle. | ||
love.graphics.clear | Clears the screen or active Canvas to the specified color. | ||
love.graphics.discard | Discards the contents of the screen or active Canvas. | 0.10.0 | |
love.graphics.draw | Draws objects on screen. | ||
love.graphics.drawInstanced | Draws many instances of a Mesh with a single draw call, using hardware geometry instancing. | 11.0 | |
love.graphics.drawLayer | Draws a layer of an Array Texture. | 11.0 | |
love.graphics.drawq | Draw a Quad with the specified Image on screen. | 0.9.0 | |
love.graphics.ellipse | Draws an ellipse. | 0.10.0 | |
love.graphics.flushBatch | Immediately renders any pending automatically batched draws. | 11.0 | |
love.graphics.line | Draws lines between points. | ||
love.graphics.point | Draws a point. | 0.3.0 | 0.10.0 |
love.graphics.points | Draws one or more points. | 0.10.0 | |
love.graphics.polygon | Draw a polygon. | 0.4.0 | |
love.graphics.present | Displays the results of drawing operations on the screen. | ||
love.graphics.print | Draws text on screen. If no Font is set, one will be created and set (once) if needed. | ||
love.graphics.printf | Draws formatted text, with word wrap and alignment. | ||
love.graphics.quad | Draws a quadrilateral shape. | 0.9.0 | |
love.graphics.rectangle | Draws a rectangle. | 0.3.2 | |
love.graphics.stencil | Draws geometry as a stencil. | 0.10.0 | |
love.graphics.triangle | Draws a triangle. | 0.9.0 |
Object Creation
Graphics State
love.graphics.getBackgroundColor | Gets the current background color. | ||
love.graphics.getBlendMode | Gets the blending mode. | 0.2.0 | |
love.graphics.getCanvas | Returns the current target Canvas. | 0.8.0 | |
love.graphics.getColor | Gets the current color. | ||
love.graphics.getColorMask | Gets the active color components used when drawing. | 0.9.0 | |
love.graphics.getColorMode | Gets the color mode (which controls how images are affected by the current color). | 0.2.0 | 0.9.0 |
love.graphics.getDefaultFilter | Returns the default scaling filters used with Images, Canvases, and Fonts. | 0.9.0 | |
love.graphics.getDefaultImageFilter | Returns the default scaling filters. | 0.8.0 | 0.9.0 |
love.graphics.getDepthMode | Gets the current depth test mode and whether writing to the depth buffer is enabled. | 11.0 | |
love.graphics.getFont | Gets the current Font object. | 0.9.0 | |
love.graphics.getFrontFaceWinding | Gets whether triangles with clockwise- or counterclockwise-ordered vertices are considered front-facing. | 11.0 | |
love.graphics.getLineJoin | Gets the line join style. | ||
love.graphics.getLineStipple | Gets the current line stipple. | 0.8.0 | |
love.graphics.getLineStyle | Gets the line style. | 0.3.2 | |
love.graphics.getLineWidth | Gets the current line width. | 0.3.2 | |
love.graphics.getMeshCullMode | Gets whether back-facing triangles in a Mesh are culled. | 11.0 | |
love.graphics.getPixelEffect | Returns the current PixelEffect. | 0.8.0 | 0.9.0 |
love.graphics.getPointSize | Gets the point size. | ||
love.graphics.getPointStyle | Gets the current point style. | 0.10.0 | |
love.graphics.getScissor | Gets the current scissor box. | 0.4.0 | |
love.graphics.getShader | Gets the current Shader. | 0.9.0 | |
love.graphics.getStackDepth | Gets the current depth of the transform / state stack (the number of pushes without corresponding pops). | 11.0 | |
love.graphics.getStencilTest | Gets the current stencil test configuration. | 0.10.0 | |
love.graphics.intersectScissor | Sets the scissor to the rectangle created by the intersection of the specified rectangle with the existing scissor. | 0.10.0 | |
love.graphics.isActive | Gets whether the graphics module is able to be used. | 0.10.0 | |
love.graphics.isGammaCorrect | Gets whether gamma-correct rendering is enabled. | 0.10.0 | |
love.graphics.isSupported | Checks for the support of graphics related functions. | 0.8.0 | 0.10.0 |
love.graphics.isWireframe | Gets whether wireframe mode is used when drawing. | 0.9.1 | |
love.graphics.reset | Resets the current graphics settings. | ||
love.graphics.setBackgroundColor | Sets the background color. | ||
love.graphics.setBlendMode | Sets the blending mode. | 0.2.0 | |
love.graphics.setCanvas | Captures drawing operations to a Canvas | 0.8.0 | |
love.graphics.setColor | Sets the color used for drawing. | ||
love.graphics.setColorMask | Sets the color mask. Enables or disables specific color components when rendering. | 0.9.0 | |
love.graphics.setColorMode | Sets the color mode (which controls how images are affected by the current color). | 0.2.0 | 0.9.0 |
love.graphics.setDefaultFilter | Sets the default scaling filters used with Images, Canvases, and Fonts. | 0.9.0 | |
love.graphics.setDefaultImageFilter | Sets the default scaling filters. | 0.8.0 | 0.9.0 |
love.graphics.setDepthMode | Configures depth testing and writing to the depth buffer. | 11.0 | |
love.graphics.setFont | Set an already-loaded Font as the current font. | ||
love.graphics.setFrontFaceWinding | Sets whether triangles with clockwise- or counterclockwise-ordered vertices are considered front-facing. | 11.0 | |
love.graphics.setInvertedStencil | Defines an inverted stencil. | 0.8.0 | 0.10.0 |
love.graphics.setLine | Sets the line width and style. | 0.9.0 | |
love.graphics.setLineJoin | Sets the line join style. | ||
love.graphics.setLineStipple | Sets the line stipple pattern. | 0.8.0 | |
love.graphics.setLineStyle | Sets the line style. | 0.3.2 | |
love.graphics.setLineWidth | Sets the line width. | 0.3.2 | |
love.graphics.setMeshCullMode | Sets whether back-facing triangles in a Mesh are culled. | 11.0 | |
love.graphics.setPixelEffect | Routes drawing operations through a pixel shader. | 0.8.0 | 0.9.0 |
love.graphics.setPoint | Sets the point size and style. | 0.9.0 | |
love.graphics.setPointSize | Sets the point size. | ||
love.graphics.setPointStyle | Sets the point style. | 0.10.0 | |
love.graphics.setRenderTarget | Captures drawing operations to a Framebuffer | 0.7.0 | 0.8.0 |
love.graphics.setScissor | Sets or disables scissor. | 0.4.0 | |
love.graphics.setShader | Routes drawing operations through a shader. | 0.9.0 | |
love.graphics.setStencil | Defines or releases a stencil. | 0.8.0 | 0.10.0 |
love.graphics.setStencilTest | Configures or disables stencil testing. | 0.10.0 | |
love.graphics.setWireframe | Sets whether wireframe lines will be used when drawing. | 0.9.1 |
Coordinate System
love.graphics.applyTransform | Applies the given Transform object to the current coordinate transformation. | 11.0 | |
love.graphics.inverseTransformPoint | Converts the given 2D position from screen-space into global coordinates. | 11.0 | |
love.graphics.origin | Resets the current coordinate transformation. | 0.9.0 | |
love.graphics.pop | Pops the current coordinate transformation from the transformation stack. | ||
love.graphics.push | Copies and pushes the current coordinate transformation to the transformation stack. | ||
love.graphics.replaceTransform | Replaces the current coordinate transformation with the given Transform object. | 11.0 | |
love.graphics.rotate | Rotates the coordinate system in two dimensions. | ||
love.graphics.scale | Scales the coordinate system in two dimensions. | ||
love.graphics.shear | Shears the coordinate system. | 0.8.0 | |
love.graphics.transformPoint | Converts the given 2D position from global coordinates into screen-space. | 11.0 | |
love.graphics.translate | Translates the coordinate system in two dimensions. |
Window
love.graphics.checkMode | Checks if a display mode is supported. | 0.9.0 | |
love.graphics.getCaption | Gets the window caption. | 0.9.0 | |
love.graphics.getDPIScale | Gets the DPI scale factor of the window. | 11.0 | |
love.graphics.getDimensions | Gets the width and height of the window. | 0.9.0 | |
love.graphics.getHeight | Gets the height in pixels of the window. | 0.2.1 | |
love.graphics.getMode | Returns the current display mode. | 0.8.0 | 0.9.0 |
love.graphics.getModes | Gets a list of supported fullscreen modes. | 0.9.0 | |
love.graphics.getPixelDimensions | Gets the width and height in pixels of the window. | 11.0 | |
love.graphics.getPixelHeight | Gets the height in pixels of the window. | 11.0 | |
love.graphics.getPixelWidth | Gets the width in pixels of the window. | 11.0 | |
love.graphics.getWidth | Gets the width in pixels of the window. | 0.2.1 | |
love.graphics.hasFocus | Checks if the game window has keyboard focus. | 0.8.0 | 0.9.0 |
love.graphics.isCreated | Checks if the window has been created. | 0.9.0 | |
love.graphics.setCaption | Sets the window caption. | 0.9.0 | |
love.graphics.setIcon | Set window icon. | 0.7.0 | 0.9.0 |
love.graphics.setMode | Changes the display mode. | 0.9.0 | |
love.graphics.toggleFullscreen | Toggles fullscreen. | 0.9.0 |
System Information
love.graphics.getCanvasFormats | Gets the available Canvas formats, and whether each is supported. | 0.9.2 | |
love.graphics.getCompressedImageFormats | Gets the available compressed image formats, and whether each is supported. | 0.9.2 | 11.0 |
love.graphics.getImageFormats | Gets the pixel formats usable for Images, and whether each is supported. | 11.0 | |
love.graphics.getMaxImageSize | Gets the max supported width or height of Images and Canvases. | 0.9.0 | 0.10.0 |
love.graphics.getMaxPointSize | Gets the max supported point size. | 0.10.0 | |
love.graphics.getRendererInfo | Gets information about the system's video card and drivers. | 0.9.0 | |
love.graphics.getStats | Gets performance-related rendering statistics. | 0.9.2 | |
love.graphics.getSupported | Gets the optional graphics features and whether they're supported. | 0.10.0 | |
love.graphics.getSystemLimit | Gets the system-dependent maximum value for a love.graphics feature. | 0.9.1 | 0.10.0 |
love.graphics.getSystemLimits | Gets the system-dependent maximum values for love.graphics features. | 0.10.0 | |
love.graphics.getTextureTypes | Gets the available texture types, and whether each is supported. | 11.0 |
Enums
AlignMode | Text alignment. | ||
ArcType | Different types of arcs that can be drawn. | 0.10.1 | |
AttributeDataType | Data types used in a Mesh's vertex format. | 0.9.0 | |
BlendAlphaMode | Different ways alpha affects color blending. | 0.10.0 | |
BlendMode | Different ways to do color blending. | 0.2.0 | |
BufferDataUsage | Usage hints for SpriteBatches, Meshes, and GraphicsBuffers to optimize data storage and access. | 0.8.0 | |
CanvasFormat | Canvas texture formats. | 0.9.0 | |
ColorMode | Controls how drawn images are affected by current color. | 0.2.0 | 0.9.0 |
CompareMode | Different types of stencil test and depth test comparisons. | 0.10.0 | |
CullMode | How Mesh geometry is culled when rendering. | 11.0 | |
DrawMode | Controls whether shapes are drawn as an outline, or filled. | ||
FilterMode | How the image is filtered when scaling. | ||
GraphicsFeature | Graphics features that can be checked for with love.graphics.getSupported. | 0.8.0 | |
GraphicsLimit | Types of system-dependent graphics limits. | 0.9.1 | |
IndexDataType | Vertex map datatype. | 11.0 | |
LineJoin | Line join style. | ||
LineStyle | The styles in which lines are drawn. | ||
MeshDrawMode | How a Mesh's vertices are used when drawing. | 0.9.0 | |
MipmapMode | Controls whether a Canvas has mipmaps, and its behaviour when it does. | 11.0 | |
PixelFormat | Pixel formats for Textures, ImageData, and CompressedImageData. | 11.0 | |
PointStyle | How points should be drawn. | 0.10.0 | |
StackType | Graphics state stack types used with love.graphics.push. | 0.9.2 | |
StencilAction | How a stencil function modifies the stencil values of pixels it touches. | 0.10.0 | |
TextureFormat | Controls the canvas texture format. | 0.9.0 | 0.10.0 |
TextureType | Types of textures (2D, cubemap, etc.) | 11.0 | |
VertexAttributeStep | The frequency at which a vertex shader fetches the vertex attribute's data from the Mesh when it's drawn. | 11.0 | |
VertexWinding | Vertex winding. | 11.0 | |
WrapMode | How the image wraps inside a large Quad. |
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info