Linux glClearColor(0, 0, 0, 0) 是透明的,不是黑色的

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12175406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:12:10  来源:igfitidea点击:

glClearColor(0, 0, 0, 0) is transparent, not black

clinuxopenglubuntufreeglut

提问by Niklas R

I'm trying to use OpenGL my first time. I was looking at some code online and then tried to write my own, but I always just got an empty (transparent) window. (I used GLUT to open the window).

我第一次尝试使用 OpenGL。我正在网上查看一些代码,然后尝试编写自己的代码,但我总是得到一个空的(透明)窗口。(我使用 GLUT 打开窗口)。

I thought I did something wrong, so I copyied the code from hereto my C source-code, and my window is still transparent. Also, the alphaparameter for glClearColor()does not seem to have any effect. Instead, the alpha-value seemsto be determined by the red, greenand blueparameters.

我以为我做错了什么,所以我将代码从这里复制到我的 C 源代码中,我的窗口仍然是透明的。此外,glClearColor()alpha参数似乎没有任何效果。相反,alpha 值似乎redgreenblue参数决定。

glClearColor(0, 0, 0, 0)
glClearColor(0, 0, 0, 1)
enter image description here

glClearColor(0, 0, 0, 0)
glClearColor(0, 0, 0, 1)
在此处输入图片说明

glClearColor(1, 0, 0, 0)
glClearColor(1, 0, 0, 1)
enter image description here

glClearColor(1, 0, 0, 0)
glClearColor(1, 0, 0, 1)
在此处输入图片说明

glClearColor(1, 1, 0, 0)
glClearColor(1, 1, 0, 1)
enter image description here

glClearColor(1, 1, 0, 0)
glClearColor(1, 1, 0, 1)
在此处输入图片说明

glClearColor(1, 0, 0, 0)
glClearColor(1, 0, 0, 1)
enter image description here

glClearColor(1, 0, 0, 0)
glClearColor(1, 0, 0, 1)
在此处输入图片说明

The alphaparameter doesn't change the result.

阿尔法参数不会改变结果。

I use Ubuntu 12.04 LTS, libgl1-mesa-dev.

我使用 Ubuntu 12.04 LTS, libgl1-mesa-dev

Is this a bug or do I do something wrong?

这是一个错误还是我做错了什么?

回答by aib

GLUT does not request an alpha buffer by default, and I suspect what you're seeing might be a fail-safe, ad hoc implementation of window transparency. Try adding:

默认情况下,GLUT 不请求 alpha 缓冲区,我怀疑您所看到的可能是窗口透明度的故障安全、临时实现。尝试添加:

glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA);

near the other GLUT init calls. Keep this functionin mind, as you'll need to modify the call again if/when you want depth or stencil buffers, or double buffering.

在其他 GLUT init 调用附近。请记住此功能,因为如果/当您需要深度或模板缓冲区或双缓冲时,您将需要再次修改调用。

回答by Muhammed Anees V

Use glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) in display mode

在显示模式下使用 glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB)