unexpected screen clearing WebGL

青春壹個敷衍的年華 提交于 2019-12-14 03:20:20

问题


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) Draw first black rect in main task queue

drawRect(10, 10, 20, 20);

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!

Thank you!


回答1:


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

You should instead use gl.bufferSubData().

check out this answer bufferData - usage parameter differences



来源:https://stackoverflow.com/questions/31818876/unexpected-screen-clearing-webgl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!