Niklas R
Niklas R

Reputation: 16890

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

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).

I thought I did something wrong, so I copyied the code from here to my C source-code, and my window is still transparent. Also, the alpha parameter for glClearColor() does not seem to have any effect. Instead, the alpha-value seems to be determined by the red, green and blue parameters.

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

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

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

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

The alpha parameter doesn't change the result.

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

Is this a bug or do I do something wrong?

Upvotes: 3

Views: 34075

Answers (2)

Muhammed Anees V
Muhammed Anees V

Reputation: 71

Use glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB) in display mode

Upvotes: 1

aib
aib

Reputation: 46991

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:

glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA);

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

Upvotes: 7

Related Questions