简体   繁体   English

WebGL:数据转换为非方形alpha纹理

[英]WebGL : data to non square alpha texture

I have a weird problem with webGL. 我对webGL有一个奇怪的问题。

I'm using a dynamically generated texture of which only the alpha channel matters. 我正在使用仅Alpha通道重要的动态生成的纹理。 Here's the code: 这是代码:

var texture  = new Uint8Array(ar); // ar is my array
gl.bindTexture(gl.TEXTURE_2D, this.transparencyTexture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, array.length, array[0].length, 0, gl.ALPHA, gl.UNSIGNED_BYTE, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);   

I'm always using a POT array' "width" and "height" but whenever "width" <> "height" it doesn't work. 我一直在使用POT阵列的“宽度”和“高度”,但是无论何时“宽度” <>“高度”都不起作用。 So it currently only works with squares. 因此,它目前仅适用于正方形。

What can be done? 该怎么办?

EDIT: 编辑:

http://jsfiddle.net/SergeJcqmn/EAmjU/9/ http://jsfiddle.net/SergeJcqmn/EAmjU/9/

In the jsfiddle, line 76 of the js is incorrect: 在jsfiddle中,js的第76行不正确:

ar.push(array[x][(array.length - 1) - y] ?  128 : 0);

I believe this should be: 我相信这应该是:

ar.push(array[x][(array[0].length - 1) - y] ?  128 : 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM