Difference between revisions of "love.graphics.setBlendMode"

m (The 'multiply' blend mode must be used with premultiplied alpha, the example given would throw an error.)
m (Example: No more bytes.)
Line 26: Line 26:
 
The default "alphamultiply" alpha mode should normally be preferred except when drawing content with pre-multiplied alpha. If content is drawn to a [[Canvas]] using the "alphamultiply" mode, the Canvas texture will have pre-multiplied alpha afterwards, so the "premultiplied" alpha mode should generally be used when drawing a Canvas to the screen.
 
The default "alphamultiply" alpha mode should normally be preferred except when drawing content with pre-multiplied alpha. If content is drawn to a [[Canvas]] using the "alphamultiply" mode, the Canvas texture will have pre-multiplied alpha afterwards, so the "premultiplied" alpha mode should generally be used when drawing a Canvas to the screen.
  
==Example==
+
== Examples ==
 
<source lang="lua">
 
<source lang="lua">
 
function love.load()
 
function love.load()
love.graphics.setBackgroundColor(54/255, 172/255, 248/255)
+
love.graphics.setBackgroundColor(.21, .67, .97)
 
end
 
end
  
 
function love.draw()
 
function love.draw()
love.graphics.setBlendMode("alpha") --Default blend mode
+
love.graphics.setBlendMode("alpha") -- Default blend mode.
love.graphics.setColor(230/255, 44/255, 123/255)
+
love.graphics.setColor(.90, .17, .48)
love.graphics.rectangle("fill", 50, 50, 100, 100)
+
love.graphics.rectangle("fill", 50,50, 100,100)
+
 
love.graphics.setColor(12/255, 100/255, 230/255)
+
love.graphics.setColor(.04, .39, .90)
 
love.graphics.setBlendMode("multiply", "premultiplied")
 
love.graphics.setBlendMode("multiply", "premultiplied")
love.graphics.rectangle("fill", 75, 75, 125, 125)
+
love.graphics.rectangle("fill", 75,75, 125,125)
 
end
 
end
 
</source>
 
</source>

Revision as of 01:07, 1 September 2022

Available since LÖVE 0.2.0
This function is not supported in earlier versions.

Sets the blending mode.

Function

Synopsis

love.graphics.setBlendMode( mode )

Arguments

BlendMode mode
The blend mode to use.

Returns

Nothing.

Function

Available since LÖVE 0.10.0
This variant is not supported in earlier versions.

Synopsis

love.graphics.setBlendMode( mode, alphamode )

Arguments

BlendMode mode
The blend mode to use.
BlendAlphaMode alphamode ("alphamultiply")
What to do with the alpha of drawn objects when blending.

Returns

Nothing.

Notes

The default "alphamultiply" alpha mode should normally be preferred except when drawing content with pre-multiplied alpha. If content is drawn to a Canvas using the "alphamultiply" mode, the Canvas texture will have pre-multiplied alpha afterwards, so the "premultiplied" alpha mode should generally be used when drawing a Canvas to the screen.

Examples

function love.load()
	love.graphics.setBackgroundColor(.21, .67, .97)
end

function love.draw()
	love.graphics.setBlendMode("alpha") -- Default blend mode.
	love.graphics.setColor(.90, .17, .48)
	love.graphics.rectangle("fill", 50,50, 100,100)

	love.graphics.setColor(.04, .39, .90)
	love.graphics.setBlendMode("multiply", "premultiplied")
	love.graphics.rectangle("fill", 75,75, 125,125)
end

See Also


Other Languages