How to make WebGL canvas transparent

后端 未结 2 2145
清歌不尽
清歌不尽 2021-02-12 15:35

Is it possible to have WebGL canvas with transparent background? I want to have contents of web page visible through the canvas.

This is what I have now

2条回答
  •  情书的邮戳
    2021-02-12 15:37

    WebGL supports alpha transparency by default, but you have to use it. Most basically, make sure you have set the clear color to transparent, gl.clearColor(0, 0, 0, 0), before your gl.clear operation.

    If you want to have semi-transparent objects drawn, that gets into blending operations and sorted drawing, but it looks like you just want the un-drawn area to be transparent, which the above is sufficient for.

提交回复
热议问题