Setting the opacity for draw and/or image functions would be sooo awesome!
And a List of blending modes in the documentation would be nice..
Besides that setting a blending mode for a single image or a single draw call would be even better!
Feature request for 0.6
- Jasoco
- Inner party member
- Posts: 3726
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Feature request for 0.6
Yeah, we've talked about it before.
To draw an image opaque:
love.graphics.setColorMode(love.color_modulate)
love.graphics.setColor(love.graphics.newColor(255,255,255,100))
The modulate part makes it work on images. The color of 255,255,255 makes sure it doesn't get colorized and is just drawn in its colors, and the 100 is the opacity. (From 0 to 255 apparently)
But you need to make sure you set Color Mode back to normal and change the opacity back to 255 before drawing images you want solid.
The blending modes so far are listed in the Constants section:
love.graphics.setBlendMode
love.blend_normal - Normal blendig mode.
love.blend_additive - Additive blending mode.
love.graphics.setColorMode
love.color_normal - Normal color mode.
love.color_modulate - Modulation color mode.
To draw an image opaque:
love.graphics.setColorMode(love.color_modulate)
love.graphics.setColor(love.graphics.newColor(255,255,255,100))
The modulate part makes it work on images. The color of 255,255,255 makes sure it doesn't get colorized and is just drawn in its colors, and the 100 is the opacity. (From 0 to 255 apparently)
But you need to make sure you set Color Mode back to normal and change the opacity back to 255 before drawing images you want solid.
The blending modes so far are listed in the Constants section:
love.graphics.setBlendMode
love.blend_normal - Normal blendig mode.
love.blend_additive - Additive blending mode.
love.graphics.setColorMode
love.color_normal - Normal color mode.
love.color_modulate - Modulation color mode.
Re: Feature request for 0.6
It should be noted that rude has posted on the wiki that color_modulate will be the default color mode. So, whenever 0.6.0 gets released (few years time I guess heh) you won't have to worry about changing the mode yourself.
- Star Crunch
- Prole
- Posts: 33
- Joined: Sun Feb 15, 2009 12:13 am
- Location: Monterrey, MX
- Contact:
Re: Feature request for 0.6
I needed this feature to port TacoShell [1] to LÖVE. You can take a look at it in the demo, if you want. It uses
my own class system and a couple helper utilities, but nothing really esoteric.
Here follows a poorly-summarized description. (So far I've only done the demo and some prototyping, so I
haven't documented much.) Some of this may be overkill for your needs, but is probably worth mentioning
to describe the code.
In the Scripts folder, these are the relevant files:
- Utility/LoveClasses.lua
This just extends the LÖVE functions that create objects, marking the new objects so I can later ask what type they are.
- Class/Game/Graphics/GraphicBase.lua
Where all the magic is, via the WithProperties() method.
Thus far, these important methods are available: SetColorPolicy(), SetColorKeep(), SetBlendModePolicy(),
SetBlendModeKeep(), SetColorModePolicy(), SetColorModeKeep().
By default, all the "keep" features are false. You just pass true or false to these. If true, you want your change
(setColor(), setBlendMode(), setColorMode()) to stick around; otherwise it gets undone after drawing.
You can pass a properties table (see the draw call below) through WithProperties(), and it will look for the following
fields: color, blend_mode, color_mode. If present, color can be either a LÖVE color or a string that
is the name of a registered color ("default", "current", and several others, including your own custom ones; see
Graphics.lua); blend_mode and color_mode can be the appropriate LÖVE constants.
If one of these keys is NOT present, the relevant policy is used to get the current value. The default policies are
"default" for color, and "normal" for both blend and color mode.
The color policies are:
- "default": Uses the registered color, "default"
- "current": Uses the color last set by setColor()
The blend mode policies are:
- "current": Uses the mode last set by setBlendMode()
- "normal": Uses normal blending mode
- "additive": Uses additive blending mode
The color mode policies are:
- "current": Uses the mode last set by setColorMode()
- "normal": Uses normal color mode
- "modulate": Uses modulate color mode
- Class/Game/Graphics/GraphicElement.lua
Wrapper for either an Image or Animation (passed via method SetObject() or the constructor); derives from
GraphicBase. You then call this wrapper to draw it, passing the draw region and an optional properties table,
which has the colors and modes and such. I've found it more flexible to keep the properties table separate
from the wrapper, but YMMV.
Initialization:
In draw():
- Class/Game/Graphics/Font.lua
Nothing in particular, just another example like GraphicElement.
- Subsystems/Graphics.lua
Color registration, and some primitive-drawing operations built on top of this feature. Note that in this case
the base object is out of reach, so you can't switch its policies or keep flags; it's only used to respond to the
properties table argument.
[1] - A slightly updated demo can be found here. The updates include the rectangle primitive functions
using this feature in Graphics.lua.
*Massive post saved for later documentation*
my own class system and a couple helper utilities, but nothing really esoteric.
Here follows a poorly-summarized description. (So far I've only done the demo and some prototyping, so I
haven't documented much.) Some of this may be overkill for your needs, but is probably worth mentioning
to describe the code.
In the Scripts folder, these are the relevant files:
- Utility/LoveClasses.lua
This just extends the LÖVE functions that create objects, marking the new objects so I can later ask what type they are.
- Class/Game/Graphics/GraphicBase.lua
Where all the magic is, via the WithProperties() method.
Thus far, these important methods are available: SetColorPolicy(), SetColorKeep(), SetBlendModePolicy(),
SetBlendModeKeep(), SetColorModePolicy(), SetColorModeKeep().
By default, all the "keep" features are false. You just pass true or false to these. If true, you want your change
(setColor(), setBlendMode(), setColorMode()) to stick around; otherwise it gets undone after drawing.
You can pass a properties table (see the draw call below) through WithProperties(), and it will look for the following
fields: color, blend_mode, color_mode. If present, color can be either a LÖVE color or a string that
is the name of a registered color ("default", "current", and several others, including your own custom ones; see
Graphics.lua); blend_mode and color_mode can be the appropriate LÖVE constants.
If one of these keys is NOT present, the relevant policy is used to get the current value. The default policies are
"default" for color, and "normal" for both blend and color mode.
The color policies are:
- "default": Uses the registered color, "default"
- "current": Uses the color last set by setColor()
The blend mode policies are:
- "current": Uses the mode last set by setBlendMode()
- "normal": Uses normal blending mode
- "additive": Uses additive blending mode
The color mode policies are:
- "current": Uses the mode last set by setColorMode()
- "normal": Uses normal color mode
- "modulate": Uses modulate color mode
- Class/Game/Graphics/GraphicElement.lua
Wrapper for either an Image or Animation (passed via method SetObject() or the constructor); derives from
GraphicBase. You then call this wrapper to draw it, passing the draw region and an optional properties table,
which has the colors and modes and such. I've found it more flexible to keep the properties table separate
from the wrapper, but YMMV.
Initialization:
Code: Select all
local image = love.graphics.newImage("OttersAndPonies.png")
background = class.New("GraphicElement", image, true) -- Last parameter corrects for centering
background_props = { color = "blue", blend_mode = "modulate" }
Code: Select all
background(0, 0, love.graphics.getWidth(), love.graphics.getHeight(), background_props)
Nothing in particular, just another example like GraphicElement.
- Subsystems/Graphics.lua
Color registration, and some primitive-drawing operations built on top of this feature. Note that in this case
the base object is out of reach, so you can't switch its policies or keep flags; it's only used to respond to the
properties table argument.
[1] - A slightly updated demo can be found here. The updates include the rectangle primitive functions
using this feature in Graphics.lua.
*Massive post saved for later documentation*
Who is online
Users browsing this forum: No registered users and 5 guests