Available since LÖVE 0.9.0
This function is not supported in earlier versions.
Creates a new Mesh.
Use Mesh:setTexture if the Mesh should be textured with an Image or Canvas when it's drawn.
This function can be slow if it is called repeatedly, such as from love.update or love.draw. If you need to use a specific resource often, create it once and store it somewhere it can be reused!
Available since LÖVE 0.10.0
This variant is not supported in earlier versions.
Creates a standard Mesh with the specified vertices.
mesh = love.graphics.newMesh( vertices, mode, usage )
table verticesnumber [1]number [2]number [3] (0)number [4] (0)number [5] (255)number [6] (255)number [7] (255)number [8] (255)MeshDrawMode mode ("fan")SpriteBatchUsage usage ("dynamic")Mesh mesh Available since LÖVE 0.10.0
This variant is not supported in earlier versions.
Creates a standard Mesh with the specified number of vertices.
mesh = love.graphics.newMesh( vertexcount, mode, usage )
number vertexcount{0,0, 0,0, 255,255,255,255}.MeshDrawMode mode ("fan")SpriteBatchUsage usage ("dynamic")Mesh meshMesh:setVertices or Mesh:setVertex and Mesh:setDrawRange can be used to specify vertex information once the Mesh is created.
Available since LÖVE 0.10.0
This variant is not supported in earlier versions.
Creates a Mesh with custom vertex attributes and the specified vertex data.
mesh = love.graphics.newMesh( vertexformat, vertices, mode, usage )
table vertexformat{attribute, ...}. Each attribute is a table which specifies a custom vertex attribute used for each vertex.
table vertices{vertex, ...} where each vertex is a table in the form of {attributecomponent, ...}.
MeshDrawMode mode ("fan")SpriteBatchUsage usage ("dynamic")Mesh meshThe values in each vertex table are in the same order as the vertex attributes in the specified vertex format. If no value is supplied for a specific vertex attribute component, it will be set to a default value of 0 if its data type is "float", or 255 if its data type is "byte".
If a custom vertex attribute uses the name "VertexPosition", "VertexTexCoord", or "VertexColor", then the vertex data for that vertex attribute will be used for the standard vertex positions, texture coordinates, or vertex colors respectively, when drawing the Mesh. Otherwise a Vertex Shader is required in order to make use of the vertex attribute when the Mesh is drawn.
A Mesh must have a "VertexPosition" attribute in order to be drawn, but it can be attached from a different Mesh via Mesh:attachAttribute.
To use a custom named vertex attribute in a Vertex Shader, it must be declared as an attribute variable of the same name. Variables can be sent from Vertex Shader code to Pixel Shader code by making a varying variable. For example:
Vertex Shader code
attribute vec2 CoolVertexAttribute;
varying vec2 CoolVariable;
vec4 position(mat4 transform_projection, vec4 vertex_position)
{
CoolVariable = CoolVertexAttribute;
return transform_projection * vertex_position;
} Pixel Shader code
varying vec2 CoolVariable;
vec4 effect(vec4 color, Image tex, vec2 texcoord, vec2 pixcoord)
{
vec4 texcolor = Texel(tex, texcoord + CoolVariable);
return texcolor * color;
} Available since LÖVE 0.10.0
This variant is not supported in earlier versions.
Creates a Mesh with custom vertex attributes and the specified number of vertices.
mesh = love.graphics.newMesh( vertexformat, vertexcount, mode, usage )
table vertexformat{attribute, ...}. Each attribute is a table which specifies a custom vertex attribute used for each vertex.
number vertexcountMeshDrawMode mode ("fan")SpriteBatchUsage usage ("dynamic")Mesh meshEach vertex attribute component is initialized to 0 if its data type is "float", or 255 if its data type is "byte". Mesh:setVertices or Mesh:setVertex and Mesh:setDrawRange can be used to specify vertex information once the Mesh is created.
If a custom vertex attribute uses the name "VertexPosition", "VertexTexCoord", or "VertexColor", then the vertex data for that vertex attribute will be used for the standard vertex positions, texture coordinates, or vertex colors respectively, when drawing the Mesh. Otherwise a Vertex Shader is required in order to make use of the vertex attribute when the Mesh is drawn.
A Mesh must have a "VertexPosition" attribute in order to be drawn, but it can be attached from a different Mesh via Mesh:attachAttribute.
Removed in LÖVE 0.10.0
This variant is not supported in that and later versions.
mesh = love.graphics.newMesh( vertices, texture, mode )
table verticesnumber [1]number [2]number [3]number [4]number [5] (255)number [6] (255)number [7] (255)number [8] (255)Texture texture (nil)MeshDrawMode mode ("fan")Mesh mesh Available since LÖVE 0.9.1 and removed in LÖVE 0.10.0
This variant is not supported in earlier or later versions.
mesh = love.graphics.newMesh( vertexcount, texture, mode )
number vertexcount{0,0, 0,0, 255,255,255,255}.Texture texture (nil)MeshDrawMode mode ("fan")Mesh meshMesh:setVertices or Mesh:setVertex and Mesh:setDrawRange can be used to specify vertex information once the Mesh is created.
function love.load()
image = love.graphics.newImage("pig.png")
local vertices = {
{
-- top-left corner (red-tinted)
0, 0, -- position of the vertex
0, 0, -- texture coordinate at the vertex position
255, 0, 0, -- color of the vertex
},
{
-- top-right corner (green-tinted)
image:getWidth(), 0,
1, 0, -- texture coordinates are in the range of [0, 1]
0, 255, 0
},
{
-- bottom-right corner (blue-tinted)
image:getWidth(), image:getHeight(),
1, 1,
0, 0, 255
},
{
-- bottom-left corner (yellow-tinted)
0, image:getHeight(),
0, 1,
255, 255, 0
},
}
-- the Mesh DrawMode "fan" works well for 4-vertex Meshes.
mesh = love.graphics.newMesh(vertices, "fan")
mesh:setTexture(image)
end
function love.draw()
love.graphics.draw(mesh, 0, 0)
end function CreateTexturedCircle(image, segments)
segments = segments or 40
local vertices = {}
-- The first vertex is at the center, and has a red tint. We're centering the circle around the origin (0, 0).
table.insert(vertices, {0, 0, 0.5, 0.5, 255, 0, 0})
-- Create the vertices at the edge of the circle.
for i=0, segments do
local angle = (i / segments) * math.pi * 2
-- Unit-circle.
local x = math.cos(angle)
local y = math.sin(angle)
-- Our position is in the range of [-1, 1] but we want the texture coordinate to be in the range of [0, 1].
local u = (x + 1) * 0.5
local v = (y + 1) * 0.5
-- The per-vertex color defaults to white.
table.insert(vertices, {x, y, u, v})
end
-- The "fan" draw mode is perfect for our circle.
local mesh = love.graphics.newMesh(vertices, "fan")
mesh:setTexture(image)
return mesh
end
function love.load()
image = love.graphics.newImage("pig.png")
mesh = CreateTexturedCircle(image)
end
function love.draw()
local radius = 100
local mx, my = love.mouse.getPosition()
-- We created a unit-circle, so we can use the scale parameter for the radius directly.
love.graphics.draw(mesh, mx, my, 0, radius, radius)
end function CreateCircle(segments)
segments = segments or 40
local vertices = {}
-- The first vertex is at the origin (0, 0) and will be the center of the circle.
table.insert(vertices, {0, 0})
-- Create the vertices at the edge of the circle.
for i=0, segments do
local angle = (i / segments) * math.pi * 2
-- Unit-circle.
local x = math.cos(angle)
local y = math.sin(angle)
table.insert(vertices, {x, y})
end
-- The "fan" draw mode is perfect for our circle.
return love.graphics.newMesh(vertices, "fan")
end
function love.load()
mesh = CreateCircle()
end
function love.draw()
local radius = 100
local mx, my = love.mouse.getPosition()
-- We created a unit-circle, so we can use the scale parameter for the radius directly.
love.graphics.draw(mesh, mx, my, 0, radius, radius)
end
© 2006–2016 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
https://love2d.org/wiki/love.graphics.newMesh