小程序Canvas WebGL 在安卓机型上背景黑色,无法透明?
发布于 4 年前 作者 xia19 9467 次浏览 来自 官方Issues

小程序Canvas  WebGL 在安卓机型上背景黑色,无法透明,请问有解决方案吗?不透明无法实现摄像头AR效果。编辑器里透明,和真机差距那么多,太坑了

2 回复

还有问题的可以试下这个代码,我是从 threeJS 源码拿出来的,在几台安卓机器上都可以透明,不加则不透明。webGLCanvasId 设置你们的ID。如果用 threeJS,canvas 和 glContext 要传到 threeJS 里面。

wx.createSelectorQuery()

        .select(`#${webGLCanvasId}`)

        .node()

        .exec((res) => {

          const canvas = res[0].node;

          const glContext = canvas.getContext(‘webgl’, {

            alpha: true,

            depth: true,

            stencil: true,

            antialias: true,

            premultipliedAlpha: true,

            preserveDrawingBuffer: false,

            powerPreference: ‘default’,

            failIfMajorPerformanceCaveat: false,

            xrCompatible: true

          });

          // 安卓手机需要调用这个来设置透明

          glContext.clearColor(0, 0, 0, 0);

          glContext.clear(glContext.COLOR_BUFFER_BIT);

        });

微信升级到7.0.7版本,我也碰到过这个坑

回到顶部