问题
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