Image 如果必须使用“新建图像”在WebGL中渲染图像
我看到的WebGL绘图图像示例都使用DOM图像对象:Image 如果必须使用“新建图像”在WebGL中渲染图像,image,browser,webgl,pixel,Image,Browser,Webgl,Pixel,我看到的WebGL绘图图像示例都使用DOM图像对象: var image = new Image(); image.src = "resources/f-texture.png"; image.addEventListener('load', function() { // Now that the image has loaded make copy it to the texture. gl.bindTexture(gl.TEXTURE_2D, texture); gl.texI
var image = new Image();
image.src = "resources/f-texture.png";
image.addEventListener('load', function() {
// Now that the image has loaded make copy it to the texture.
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA,gl.UNSIGNED_BYTE, image);
gl.generateMipmap(gl.TEXTURE_2D);
});
想知道是否有办法将像素放在ArrayBuffer或其他东西中,而不是使用图像
对象,然后将其绘制为图像。如果是这样的话,一般来说,代码似乎可以实现这一点。那就太好了,因为这样我就可以将像素数据用于其他事情,这样就不会重复下载图像像素数据。您可能应该这样做
是的,可以从ArrayBuffer将数据加载到纹理
gl.bindTexure(gl.TEXTURE_2D, tex);
const data = new Uint32Array([
255, 0, 0, 255, // red
0, 255, 0, 255, // green
0, 0, 255, 255, // blue
255, 255, 0, 255, // yellow
]);
const level = 0;
const internalFormat = gl.RGBA;
const width = 2;
const height = 2;
const border = 0;
const format = gl.RGBA;
const type = gl.UNSIGNED_BYTE
gl.texImage2D(gl.TEXTURE_2D, level, internalFormat, width, height, border,
format, type, data);
gl.generateMipmap(gl.TEXTURE_2D);