--- title: WebGLRenderingContext.blendColor() slug: Web/API/WebGLRenderingContext/blendColor tags: - API - Method - Reference - WebGL - WebGLRenderingContext translation_of: Web/API/WebGLRenderingContext/blendColor ---
{{APIRef("WebGL")}}

WebGL APIWebGLRenderingContext.blendColor() 方法用于设置源和目标混合因子。

语法

void gl.blendColor(red, green, blue, alpha);

参数

red
{{domxref("GLclampf")}} 红色分量的范围为0到1。
green
{{domxref("GLclampf")}} 红色分量的范围为0到1。
blue
{{domxref("GLclampf")}} 红色分量的为0到1。
alpha
{{domxref("GLclampf")}} 组件(透明度)的范围在0到1。

返回值

None.

示例

要设置混合颜色,请使用:

gl.blendColor(0, 0.5, 1, 1);

要获得混合颜色,请查询返回 {{jsxref("Float32Array")}} 的 BLEND_COLOR 常量。

gl.getParameter(gl.BLEND_COLOR);
// Float32Array[0, 0.5, 1, 1]

规范

Specification Status Comment
{{SpecName('WebGL', "#5.14.3", "blendColor")}} {{Spec2('WebGL')}} Initial definition.
{{SpecName('OpenGL ES 2.0', "glBlendColor.xml", "glBlendColor")}} {{Spec2('OpenGL ES 2.0')}} Man page of the OpenGL API.

浏览器兼容性

{{Compat("api/WebGLRenderingContext", "WebGLRenderingContext.blendColor")}}

另见