我成功地从图像创建了一个WebGL纹理并将其绘制到一个canvas元素中.
function initTexture(src) {
texture = gl.createTexture();
texture.image = new Image();
texture.image.onload = function() {
handleLoadedTexture(texture)
}
texture.image.src = src;
}
Run Code Online (Sandbox Code Playgroud)
我还试图从这些数据类型之一创建纹理,但没有成功.
是否可以使用图像的像素阵列创建纹理?或者换句话说:是否可以从像素数组中创建JS Image对象?
编辑:
像素阵列看起来像这样[r,g,b,a,r,g,b,a,r,g,b,a,...],每个值的范围为{0..255}.我想用给定数组中的像素创建纹理.