--- title: WebGLRenderingContext.clearColor() slug: Web/API/WebGLRenderingContext/clearColor translation_of: Web/API/WebGLRenderingContext/clearColor ---
WebGL API 的 WebGLRenderingContext.clearColor()
方法用于设置清空颜色缓冲时的颜色值。
这指定调用 {{domxref("WebGLRenderingContext.clear", "clear()")}} 方法时使用的颜色值。这些值在0到1的范围间。
void gl.clearColor(red, green, blue, alpha);
red
green
blue
alpha
无。
gl.clearColor(1, 0.5, 0.5, 3);
要获取当前的清除颜色,传入COLOR_CLEAR_VALUE常量,返回
{{jsxref("Float32Array")}}。
gl.getParameter(gl.COLOR_CLEAR_VALUE); // Float32Array[1, 0.5, 0.5, 1]
Specification | Status | Comment |
---|---|---|
{{SpecName('WebGL', "#5.14.3", "clearColor")}} | {{Spec2('WebGL')}} | Initial definition. |
{{SpecName('OpenGL ES 2.0', "glClearColor.xml", "glClearColor")}} | {{Spec2('OpenGL ES 2.0')}} | Man page of the OpenGL API. |
{{Compat("api/WebGLRenderingContext", "WebGLRenderingContext.clearColor")}}