|
|
|||
File indexing completed on 2026-06-02 08:58:13
0001 //////////////////////////////////////////////////////////// 0002 // 0003 // SFML - Simple and Fast Multimedia Library 0004 // Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) 0005 // 0006 // This software is provided 'as-is', without any express or implied warranty. 0007 // In no event will the authors be held liable for any damages arising from the use of this software. 0008 // 0009 // Permission is granted to anyone to use this software for any purpose, 0010 // including commercial applications, and to alter it and redistribute it freely, 0011 // subject to the following restrictions: 0012 // 0013 // 1. The origin of this software must not be misrepresented; 0014 // you must not claim that you wrote the original software. 0015 // If you use this software in a product, an acknowledgment 0016 // in the product documentation would be appreciated but is not required. 0017 // 0018 // 2. Altered source versions must be plainly marked as such, 0019 // and must not be misrepresented as being the original software. 0020 // 0021 // 3. This notice may not be removed or altered from any source distribution. 0022 // 0023 //////////////////////////////////////////////////////////// 0024 0025 #ifndef SFML_BLENDMODE_HPP 0026 #define SFML_BLENDMODE_HPP 0027 0028 //////////////////////////////////////////////////////////// 0029 // Headers 0030 //////////////////////////////////////////////////////////// 0031 #include <SFML/Graphics/Export.hpp> 0032 0033 0034 namespace sf 0035 { 0036 0037 //////////////////////////////////////////////////////////// 0038 /// \brief Blending modes for drawing 0039 /// 0040 //////////////////////////////////////////////////////////// 0041 struct SFML_GRAPHICS_API BlendMode 0042 { 0043 //////////////////////////////////////////////////////// 0044 /// \brief Enumeration of the blending factors 0045 /// 0046 /// The factors are mapped directly to their OpenGL equivalents, 0047 /// specified by glBlendFunc() or glBlendFuncSeparate(). 0048 //////////////////////////////////////////////////////// 0049 enum Factor 0050 { 0051 Zero, //!< (0, 0, 0, 0) 0052 One, //!< (1, 1, 1, 1) 0053 SrcColor, //!< (src.r, src.g, src.b, src.a) 0054 OneMinusSrcColor, //!< (1, 1, 1, 1) - (src.r, src.g, src.b, src.a) 0055 DstColor, //!< (dst.r, dst.g, dst.b, dst.a) 0056 OneMinusDstColor, //!< (1, 1, 1, 1) - (dst.r, dst.g, dst.b, dst.a) 0057 SrcAlpha, //!< (src.a, src.a, src.a, src.a) 0058 OneMinusSrcAlpha, //!< (1, 1, 1, 1) - (src.a, src.a, src.a, src.a) 0059 DstAlpha, //!< (dst.a, dst.a, dst.a, dst.a) 0060 OneMinusDstAlpha //!< (1, 1, 1, 1) - (dst.a, dst.a, dst.a, dst.a) 0061 }; 0062 0063 //////////////////////////////////////////////////////// 0064 /// \brief Enumeration of the blending equations 0065 /// 0066 /// The equations are mapped directly to their OpenGL equivalents, 0067 /// specified by glBlendEquation() or glBlendEquationSeparate(). 0068 //////////////////////////////////////////////////////// 0069 enum Equation 0070 { 0071 Add, //!< Pixel = Src * SrcFactor + Dst * DstFactor 0072 Subtract, //!< Pixel = Src * SrcFactor - Dst * DstFactor 0073 ReverseSubtract, //!< Pixel = Dst * DstFactor - Src * SrcFactor 0074 Min, //!< Pixel = min(Dst, Src) 0075 Max //!< Pixel = max(Dst, Src) 0076 }; 0077 0078 //////////////////////////////////////////////////////////// 0079 /// \brief Default constructor 0080 /// 0081 /// Constructs a blending mode that does alpha blending. 0082 /// 0083 //////////////////////////////////////////////////////////// 0084 BlendMode(); 0085 0086 //////////////////////////////////////////////////////////// 0087 /// \brief Construct the blend mode given the factors and equation. 0088 /// 0089 /// This constructor uses the same factors and equation for both 0090 /// color and alpha components. It also defaults to the Add equation. 0091 /// 0092 /// \param sourceFactor Specifies how to compute the source factor for the color and alpha channels. 0093 /// \param destinationFactor Specifies how to compute the destination factor for the color and alpha channels. 0094 /// \param blendEquation Specifies how to combine the source and destination colors and alpha. 0095 /// 0096 //////////////////////////////////////////////////////////// 0097 BlendMode(Factor sourceFactor, Factor destinationFactor, Equation blendEquation = Add); 0098 0099 //////////////////////////////////////////////////////////// 0100 /// \brief Construct the blend mode given the factors and equation. 0101 /// 0102 /// \param colorSourceFactor Specifies how to compute the source factor for the color channels. 0103 /// \param colorDestinationFactor Specifies how to compute the destination factor for the color channels. 0104 /// \param colorBlendEquation Specifies how to combine the source and destination colors. 0105 /// \param alphaSourceFactor Specifies how to compute the source factor. 0106 /// \param alphaDestinationFactor Specifies how to compute the destination factor. 0107 /// \param alphaBlendEquation Specifies how to combine the source and destination alphas. 0108 /// 0109 //////////////////////////////////////////////////////////// 0110 BlendMode(Factor colorSourceFactor, Factor colorDestinationFactor, 0111 Equation colorBlendEquation, Factor alphaSourceFactor, 0112 Factor alphaDestinationFactor, Equation alphaBlendEquation); 0113 0114 //////////////////////////////////////////////////////////// 0115 // Member Data 0116 //////////////////////////////////////////////////////////// 0117 Factor colorSrcFactor; //!< Source blending factor for the color channels 0118 Factor colorDstFactor; //!< Destination blending factor for the color channels 0119 Equation colorEquation; //!< Blending equation for the color channels 0120 Factor alphaSrcFactor; //!< Source blending factor for the alpha channel 0121 Factor alphaDstFactor; //!< Destination blending factor for the alpha channel 0122 Equation alphaEquation; //!< Blending equation for the alpha channel 0123 }; 0124 0125 //////////////////////////////////////////////////////////// 0126 /// \relates BlendMode 0127 /// \brief Overload of the == operator 0128 /// 0129 /// \param left Left operand 0130 /// \param right Right operand 0131 /// 0132 /// \return True if blending modes are equal, false if they are different 0133 /// 0134 //////////////////////////////////////////////////////////// 0135 SFML_GRAPHICS_API bool operator ==(const BlendMode& left, const BlendMode& right); 0136 0137 //////////////////////////////////////////////////////////// 0138 /// \relates BlendMode 0139 /// \brief Overload of the != operator 0140 /// 0141 /// \param left Left operand 0142 /// \param right Right operand 0143 /// 0144 /// \return True if blending modes are different, false if they are equal 0145 /// 0146 //////////////////////////////////////////////////////////// 0147 SFML_GRAPHICS_API bool operator !=(const BlendMode& left, const BlendMode& right); 0148 0149 //////////////////////////////////////////////////////////// 0150 // Commonly used blending modes 0151 //////////////////////////////////////////////////////////// 0152 SFML_GRAPHICS_API extern const BlendMode BlendAlpha; //!< Blend source and dest according to dest alpha 0153 SFML_GRAPHICS_API extern const BlendMode BlendAdd; //!< Add source to dest 0154 SFML_GRAPHICS_API extern const BlendMode BlendMultiply; //!< Multiply source and dest 0155 SFML_GRAPHICS_API extern const BlendMode BlendMin; //!< Take minimum between source and dest 0156 SFML_GRAPHICS_API extern const BlendMode BlendMax; //!< Take maximum between source and dest 0157 SFML_GRAPHICS_API extern const BlendMode BlendNone; //!< Overwrite dest with source 0158 0159 } // namespace sf 0160 0161 0162 #endif // SFML_BLENDMODE_HPP 0163 0164 0165 //////////////////////////////////////////////////////////// 0166 /// \class sf::BlendMode 0167 /// \ingroup graphics 0168 /// 0169 /// sf::BlendMode is a class that represents a blend mode. A blend 0170 /// mode determines how the colors of an object you draw are 0171 /// mixed with the colors that are already in the buffer. 0172 /// 0173 /// The class is composed of 6 components, each of which has its 0174 /// own public member variable: 0175 /// \li %Color Source Factor (@ref colorSrcFactor) 0176 /// \li %Color Destination Factor (@ref colorDstFactor) 0177 /// \li %Color Blend Equation (@ref colorEquation) 0178 /// \li Alpha Source Factor (@ref alphaSrcFactor) 0179 /// \li Alpha Destination Factor (@ref alphaDstFactor) 0180 /// \li Alpha Blend Equation (@ref alphaEquation) 0181 /// 0182 /// The source factor specifies how the pixel you are drawing contributes 0183 /// to the final color. The destination factor specifies how the pixel 0184 /// already drawn in the buffer contributes to the final color. 0185 /// 0186 /// The color channels RGB (red, green, blue; simply referred to as 0187 /// color) and A (alpha; the transparency) can be treated separately. This 0188 /// separation can be useful for specific blend modes, but most often you 0189 /// won't need it and will simply treat the color as a single unit. 0190 /// 0191 /// The blend factors and equations correspond to their OpenGL equivalents. 0192 /// In general, the color of the resulting pixel is calculated according 0193 /// to the following formula (\a src is the color of the source pixel, \a dst 0194 /// the color of the destination pixel, the other variables correspond to the 0195 /// public members, with the equations being + or - operators): 0196 /// \code 0197 /// dst.rgb = colorSrcFactor * src.rgb (colorEquation) colorDstFactor * dst.rgb 0198 /// dst.a = alphaSrcFactor * src.a (alphaEquation) alphaDstFactor * dst.a 0199 /// \endcode 0200 /// All factors and colors are represented as floating point numbers between 0201 /// 0 and 1. Where necessary, the result is clamped to fit in that range. 0202 /// 0203 /// The most common blending modes are defined as constants 0204 /// in the sf namespace: 0205 /// 0206 /// \code 0207 /// sf::BlendMode alphaBlending = sf::BlendAlpha; 0208 /// sf::BlendMode additiveBlending = sf::BlendAdd; 0209 /// sf::BlendMode multiplicativeBlending = sf::BlendMultiply; 0210 /// sf::BlendMode noBlending = sf::BlendNone; 0211 /// \endcode 0212 /// 0213 /// In SFML, a blend mode can be specified every time you draw a sf::Drawable 0214 /// object to a render target. It is part of the sf::RenderStates compound 0215 /// that is passed to the member function sf::RenderTarget::draw(). 0216 /// 0217 /// \see sf::RenderStates, sf::RenderTarget 0218 /// 0219 ////////////////////////////////////////////////////////////
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|