我正在通过LibGDX框架,它提供了一个包装器来进行opengl调用。 我经常遇到以下一对功能:
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);文档 (来自OpenGL)解释了glClearColor允许您:
指定清除颜色缓冲区时使用的红色,绿色,蓝色和alpha值。
在这里选择特定的清晰颜色的目的是什么,当它被渲染的任何东西立即覆盖时? 你应该选择与你的场景相匹配的颜色吗? 它是否用于设置场景的背景?
I'm working my way through the LibGDX framework, which provides a wrapper to make opengl calls. I regularly come across the following pair of functions:
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);The documentation(from OpenGL) explains that glClearColor allows you to:
Specify the red, green, blue, and alpha values used when the color buffers are cleared.
What is the purpose of selecting a specific clear color here, when it is then immediately overwritten by whatever gets rendered? Should you choose a color that matches your scene? Is it used to set the background for the scene?
最满意答案
如果实际上覆盖了渲染的每个帧中的每个像素,则根本不需要清除颜色缓冲区(但通常,您仍然必须清除深度缓冲区)。
但是,有许多用例需要清除缓冲区,并且能够选择背景颜色是一个有用的功能。
If you do actually overwrite every pixel in every frame you render, you don't need to clear the color buffer at all (but usually, you still have to clear the depth buffer).
However, there are lots of use cases where a cleared buffer is required, and being able to select the background color is a useful feature there.
更多推荐
发布评论