GDN9
GDN9

Reputation: 339

OpenGL Render to Transparent Texture

I have a system to render different objects into different RGBA textures using OpenGL in C++. I'd like to layer these textures on top of eachother, but my problem is that each texture has the glClearColor rendered into it.

How to tell OpenGL to make the ClearColor parts of the texture transparent (0.0f alpha), so I can still see parts of layers behind other layers?

Upvotes: 5

Views: 1675

Answers (1)

samgak
samgak

Reputation: 24417

The fourth parameter of glClearColor allows you to specify an alpha value to set when you clear the render target, so you can just pass 0 to make it clear to transparent.

Your render target obviously needs to have an alpha channel. Also, the clearing of the alpha channel using the value specified using glClearColor can be enabled or disabled using glColorMask.

Upvotes: 3

Related Questions