最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to clear a rectangle area in WebGL? - Stack Overflow

programmeradmin3浏览0评论

WebGL has a clear method that clears an entire surface. What's the best way to clear just a particular rectangle of the surface? For example I want to set a 100x100 box of pixels starting at (50, 50) to all zeroes (ARGB 0, 0, 0, 0). All I can think of right now is drawing a quad with a fragment shader that writes zeroes. Is there not an easier way?

WebGL has a clear method that clears an entire surface. What's the best way to clear just a particular rectangle of the surface? For example I want to set a 100x100 box of pixels starting at (50, 50) to all zeroes (ARGB 0, 0, 0, 0). All I can think of right now is drawing a quad with a fragment shader that writes zeroes. Is there not an easier way?

Share Improve this question asked Jul 18, 2012 at 15:13 AshleysBrainAshleysBrain 22.6k16 gold badges91 silver badges125 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 16

You can use the SCISSOR test to constrain clearing (and rendering in general) to a rectangle.

// turn on the scissor test.
gl.enable(gl.SCISSOR_TEST);

// set the scissor rectangle.
gl.scissor(x, y, width, height);

// clear.
gl.clearColor(r, g, b, a);
gl.clear(gl.COLOR_BUFFER_BIT ...);

// turn off the scissor test so you can render like normal again.
gl.disable(gl.SCISSOR_TEST);

anything outside the viewport if within the webgl context will be drawn, anything outside scissor will be clipped and not drawn at all !

发布评论

评论列表(0)

  1. 暂无评论