意外的屏幕清除 WebGL [英] unexpected screen clearing WebGL

查看:47
本文介绍了意外的屏幕清除 WebGL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天!我需要有关 webgl 的帮助!根据 http://www.html5rocks.com/en/tutorials/webgl/webgl_fundamentals/#disqus_thread教程,我创建了我的问题的简单演示:https://jsfiddle.net/kurz/o2116mz2/1/.

Good day! I need a help with webgl! According to http://www.html5rocks.com/en/tutorials/webgl/webgl_fundamentals/#disqus_thread tutorial, I created simple demo of my problem: https://jsfiddle.net/kurz/o2116mz2/1/.

1) 在主任务队列中绘制第一个黑色矩形

1) Draw first black rect in main task queue

drawRect(10, 10, 20, 20);

2) 尝试在超时时间内绘制相同的矩形,然后整个场景将被清除,然后才绘制矩形.

2) Try to draw same rect in timeout and the whole scene will be cleared and only after that the rect is drawing.

setTimeout(function(){drawRect(30, 30, 20, 20);}, 1000);

我的问题是如何在使用计时器绘制方法时避免屏幕清除.换句话说,我想在这个例子中看到两个矩形!

My question is how to avoid screen clearing when draw method using timers. In other words I want to see both rects in this example!

谢谢!

推荐答案

这是因为您使用的 gl.bufferData() 实际上正在替换您的场景内容.

it is because you are using gl.bufferData() which is actually replacing your scene's content.

您应该改用 gl.bufferSubData().

You should instead use gl.bufferSubData().

看看这个答案bufferData - 使用参数差异

这篇关于意外的屏幕清除 WebGL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆