Gambas文档
编译和安装
错误消息
代码片段
待办事项
废弃的组件
教程
开发环境文档
开发者文档
名词解释
如何操作
说明
维基手册
维基搜索
维基许可协议
文档
应用程序仓库
语言概览
语言索引
主题
组件
gb
gb.args
gb.cairo
gb.chart
gb.clipper
gb.complex
gb.compress
gb.crypt
gb.data
gb.db
gb.db.form
gb.db.mysql
gb.db.odbc
gb.db.postgresql
gb.db.sqlite2
gb.db.sqlite3
gb.dbus
gb.dbus.trayicon
gb.debug
gb.desktop
gb.desktop.x11
gb.eval
gb.eval.highlight
gb.form
gb.form.dialog
gb.form.editor
gb.form.htmlview
gb.form.mdi
gb.form.print
gb.form.terminal
gb.gmp
gb.gsl
gb.gtk
gb.gtk3
gb.gtk3.opengl
gb.gtk3.webview
gb.gui
gb.gui.qt
gb.gui.qt.ext
gb.gui.trayicon
gb.gui.webview
gb.hash
gb.highlight
gb.image
gb.image.effect
gb.image.io
gb.inotify
gb.logging
gb.map
gb.media
gb.media.form
gb.mime
gb.mongodb
gb.mysql
gb.ncurses
gb.net
gb.net.curl
gb.net.pop3
gb.net.smtp
gb.opengl
Gl
gb.opengl.glsl
gb.opengl.glu
gb.opengl.sge
gb.openssl
gb.option
gb.pcre
gb.pdf
gb.poppler
gb.qt4
gb.qt4.ext
gb.qt4.opengl
gb.qt4.webkit
gb.qt4.webview
gb.qt5
gb.qt5.ext
gb.qt5.opengl
gb.qt5.webview
gb.qt6
gb.qt6.ext
gb.qt6.opengl
gb.qt6.webview
gb.report
gb.report2
gb.sdl
gb.sdl2
gb.sdl2.audio
gb.settings
gb.signal
gb.term
gb.test
gb.util
gb.util.web
gb.v4l
gb.vb
gb.web
gb.web.feed
gb.web.form
gb.web.gui
gb.xml
gb.xml.html
gb.xml.rpc
gb.xml.xslt
最近的修改

Gl.BlendFunc (gb.opengl)

Static Sub BlendFunc ( SrcFactor As Integer, DstFactor As Integer )

Specify pixel arithmetic.

Parameters

sfactor

Specifies how the red, green, blue, and alpha source blending factors are computed. The initial value is Gl.ONE.
dfactor

Specifies how the red, green, blue, and alpha destination blending factors are computed. The following symbolic constants are accepted: Gl.ZERO, Gl.ONE, Gl.SRC_COLOR, Gl.ONE_MINUS_SRC_COLOR, Gl.DST_COLOR, Gl.ONE_MINUS_DST_COLOR, Gl.SRC_ALPHA, Gl.ONE_MINUS_SRC_ALPHA, Gl.DST_ALPHA, Gl.ONE_MINUS_DST_ALPHA. Gl.CONSTANT_COLOR, Gl.ONE_MINUS_CONSTANT_COLOR, Gl.CONSTANT_ALPHA, and Gl.ONE_MINUS_CONSTANT_ALPHA. The initial value is Gl.ZERO.

Description

Pixels can be drawn using a function that blends the incoming (source) RGBA values with the RGBA values that are already in the frame buffer (the destination values). Blending is initially disabled. Use Gl.Enable and Gl.Disable with argument Gl.BLEND to enable and disable blending.

Gl.BlendFunc defines the operation of blending when it is enabled. sfactor specifies which method is used to scale the source color components. dfactor specifies which method is used to scale the destination color components. Both parameters must be one of the following symbolic constants: Gl.ZERO, Gl.ONE, Gl.SRC_COLOR, Gl.ONE_MINUS_SRC_COLOR, Gl.DST_COLOR, Gl.ONE_MINUS_DST_COLOR, Gl.SRC_ALPHA, Gl.ONE_MINUS_SRC_ALPHA, Gl.DST_ALPHA, Gl.ONE_MINUS_DST_ALPHA, Gl.CONSTANT_COLOR, Gl.ONE_MINUS_CONSTANT_COLOR, Gl.CONSTANT_ALPHA, Gl.ONE_MINUS_CONSTANT_ALPHA, Gl.SRC_ALPHA_SATURATE, Gl.SRC1_COLOR, Gl.ONE_MINUS_SRC1_COLOR, Gl.SRC1_ALPHA, and Gl.ONE_MINUS_SRC1_ALPHA. The possible methods are described in the following table. Each method defines four scale factors, one each for red, green, blue, and alpha. In the table and in subsequent equations, first source, second source and destination color components are referred to as R s0 G s0 B s0 A s0 , R s1 G s1 B s1 A s1 and R d G d B d A d , respectively. The color specified by Gl.BlendColor is referred to as R c G c B c A c . They are understood to have integer values between 0 and k R k G k B k A , where

k c 2 m c - 1

and m R m G m B m A is the number of red, green, blue, and alpha bitplanes.

Source and destination scale factors are referred to as s R s G s B s A and d R d G d B d A . The scale factors described in the table, denoted f R f G f B f A , represent either source or destination factors. All scale factors have range 0 1 .

Parameter f R f G f B f A
Gl.ZERO 0 0 0 0
Gl.ONE 1 1 1 1
Gl.SRC_COLOR R s0 k R G s0 k G B s0 k B A s0 k A
Gl.ONE_MINUS_SRC_COLOR 1 1 1 1 - R s0 k R G s0 k G B s0 k B A s0 k A
Gl.DST_COLOR R d k R G d k G B d k B A d k A
Gl.ONE_MINUS_DST_COLOR 1 1 1 1 - R d k R G d k G B d k B A d k A
Gl.SRC_ALPHA A s0 k A A s0 k A A s0 k A A s0 k A
Gl.ONE_MINUS_SRC_ALPHA 1 1 1 1 - A s0 k A A s0 k A A s0 k A A s0 k A
Gl.DST_ALPHA A d k A A d k A A d k A A d k A
Gl.ONE_MINUS_DST_ALPHA 1 1 1 1 - A d k A A d k A A d k A A d k A
Gl.CONSTANT_COLOR R c G c B c A c
Gl.ONE_MINUS_CONSTANT_COLOR 1 1 1 1 - R c G c B c A c
Gl.CONSTANT_ALPHA A c A c A c A c
Gl.ONE_MINUS_CONSTANT_ALPHA 1 1 1 1 - A c A c A c A c
Gl.SRC_ALPHA_SATURATE i i i 1
Gl.SRC1_COLOR R s1 k R G s1 k G B s1 k B A s1 k A
Gl.ONE_MINUS_SRC1_COLOR 1 1 1 1 - R s1 k R G s1 k G B s1 k B A s1 k A
Gl.SRC1_ALPHA A s1 k A A s1 k A A s1 k A A s1 k A
Gl.ONE_MINUS_SRC1_ALPHA 1 1 1 1 - A s1 k A A s1 k A A s1 k A A s1 k A

In the table,

i min A s k A - A d k A

To determine the blended RGBA values of a pixel, the system uses the following equations:

R d min k R R s s R + R d d R G d min k G G s s G + G d d G B d min k B B s s B + B d d B A d min k A A s s A + A d d A

Despite the apparent precision of the above equations, blending arithmetic is not exactly specified, because blending operates with imprecise integer color values. However, a blend factor that should be equal to 1 is guaranteed not to modify its multiplicand, and a blend factor equal to 0 reduces its multiplicand to 0. For example, when sfactor is Gl.SRC_ALPHA, dfactor is Gl.ONE_MINUS_SRC_ALPHA, and A s is equal to k A , the equations reduce to simple replacement:

R d R s G d G s B d B s A d A s

Examples

Transparency is best implemented using blend function (Gl.SRC_ALPHA, Gl.ONE_MINUS_SRC_ALPHA) with primitives sorted from farthest to nearest. Note that this transparency calculation does not require the presence of alpha bitplanes in the frame buffer.

Blend function (Gl.SRC_ALPHA, Gl.ONE_MINUS_SRC_ALPHA) is also useful for rendering antialiased points and lines in arbitrary order.

Polygon antialiasing is optimized using blend function (Gl.SRC_ALPHA_SATURATE, Gl.ONE) with polygons sorted from nearest to farthest. (See the Gl.Enable, Gl.Disable reference page and the Gl.POLYGON_SMOOTH argument for information on polygon antialiasing.) Destination alpha bitplanes, which must be present for this blend function to operate correctly, store the accumulated coverage.

Notes

Incoming (source) alpha is correctly thought of as a material opacity, ranging from 1.0 ( K A ), representing complete opacity, to 0.0 (0), representing complete transparency.

When more than one color buffer is enabled for drawing, the GL performs blending separately for each enabled buffer, using the contents of that buffer for destination color. (See Gl.DrawBuffer.)

When dual source blending is enabled (i.e., one of the blend factors requiring the second color input is used), the maximum number of enabled draw buffers is given by Gl.MAX_DUAL_SOURCE_DRAW_BUFFERS, which may be lower than Gl.MAX_DRAW_BUFFERS.

Errors

Gl.INVALID_ENUM is generated if either sfactor or dfactor is not an accepted value.

Associated Gets

Gl.Get with argument Gl.BLEND_SRC

Gl.Get with argument Gl.BLEND_DST

Gl.IsEnabled with argument Gl.BLEND

See Also

Gl.BlendColor, Gl.BlendEquation, Gl.BlendFuncSeparate, Gl.Clear, Gl.DrawBuffer, Gl.Enable, Gl.LogicOp, Gl.StencilFunc


Copyright © 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB.

➡ See original documentation