module Graphics.GL.Low.Blending where
import Data.Default
import Graphics.GL
import Graphics.GL.Low.Classes
enableBlending :: Blending -> IO ()
enableBlending (Blending s d f (r,g,b,a)) = do
glBlendFunc (toGL s) (toGL d)
glBlendEquation (toGL f)
let c = realToFrac
glBlendColor (c r) (c g) (c b) (c a)
glEnable GL_BLEND
disableBlending :: IO ()
disableBlending = glDisable GL_BLEND
basicBlending :: Blending
basicBlending = def
{ sFactor = BlendSourceAlpha
, dFactor = BlendOneMinusSourceAlpha }
data Blending = Blending
{ sFactor :: BlendFactor
, dFactor :: BlendFactor
, blendFunc :: BlendEquation
, blendColor :: (Float,Float,Float,Float) }
instance Default Blending where
def = Blending
{ sFactor = BlendOne
, dFactor = BlendZero
, blendFunc = FuncAdd
, blendColor = (0,0,0,0) }
data BlendEquation =
FuncAdd |
FuncSubtract |
FuncReverseSubtract
deriving Show
instance Default BlendEquation where
def = FuncAdd
instance ToGL BlendEquation where
toGL FuncAdd = GL_FUNC_ADD
toGL FuncSubtract = GL_FUNC_SUBTRACT
toGL FuncReverseSubtract = GL_FUNC_REVERSE_SUBTRACT
data BlendFactor =
BlendOne |
BlendZero |
BlendSourceColor |
BlendOneMinusSourceColor |
BlendDestColor |
BlendOneMinusDestColor |
BlendSourceAlpha |
BlendOneMinusSourceAlpha |
BlendDestAlpha |
BlendOneMinusDestAlpha |
BlendConstantColor |
BlendOneMinusConstantColor |
BlendConstantAlpha |
BlendOneMinusConstantAlpha
deriving Show
instance ToGL BlendFactor where
toGL BlendOne = GL_ONE
toGL BlendZero = GL_ZERO
toGL BlendSourceColor = GL_SRC_COLOR
toGL BlendOneMinusSourceColor = GL_ONE_MINUS_SRC_COLOR
toGL BlendDestColor = GL_DST_COLOR
toGL BlendOneMinusDestColor = GL_ONE_MINUS_DST_COLOR
toGL BlendSourceAlpha = GL_SRC_ALPHA
toGL BlendOneMinusSourceAlpha = GL_ONE_MINUS_SRC_ALPHA
toGL BlendDestAlpha = GL_DST_ALPHA
toGL BlendOneMinusDestAlpha = GL_ONE_MINUS_DST_ALPHA
toGL BlendConstantColor = GL_ONE_MINUS_CONSTANT_COLOR
toGL BlendOneMinusConstantColor = GL_ONE_MINUS_CONSTANT_COLOR
toGL BlendConstantAlpha = GL_CONSTANT_ALPHA
toGL BlendOneMinusConstantAlpha = GL_ONE_MINUS_CONSTANT_ALPHA