我在 WebGL 中的图像渲染有问题:我有一个画布,一个四边形占据整个画布,一个纹理应该映射到整个四边形(我已经设置了正确的纹理坐标)。
该图像是一个包含 RGB 数据(按此顺序)的 Uint8array,图像为 1024*768 像素。我有正确的缓冲区。这是图像的链接。
问题如下:当渲染到 WebGL 中时,我的图片变得模糊不清,即使我有一个图像大小的画布。看下面的结果:
现在是代码:这是我用来创建纹理句柄的代码:
//texture
that.Texture = that.gl.createTexture();
that.gl.bindTexture(that.gl.TEXTURE_2D, that.Texture);
// Set the parameters so we can render any size image.
that.gl.texParameteri(that.gl.TEXTURE_2D, that.gl.TEXTURE_WRAP_S, that.gl.CLAMP_TO_EDGE);
that.gl.texParameteri(that.gl.TEXTURE_2D, that.gl.TEXTURE_WRAP_T, that.gl.CLAMP_TO_EDGE);
that.gl.texParameteri(that.gl.TEXTURE_2D, that.gl.TEXTURE_MIN_FILTER, that.gl.NEAREST);
that.gl.texParameteri(that.gl.TEXTURE_2D, that.gl.TEXTURE_MAG_FILTER, that.gl.NEAREST);
数据按如下方式加载到纹理上:
this.gl.texImage2D(this.gl.TEXTURE_2D, 0, this.gl.RGB, this.m_iImageWidth, this.m_iImageHeight,
0, this.gl.RGB, this.gl.UNSIGNED_BYTE, this.m_aImage);
最后,这是我使用的片段着色器:
precision mediump float;
uniform sampler2D u_image;
varying vec2 v_texCoord;
void main()
{
gl_FragColor = texture2D(u_image, v_texCoord);
}
我尝试了很多选项,从过滤到设置样式选项图像渲染像素化,将图像转换为 RGBA 并为其赋予 RGBA 值,结果始终是相同的糟糕纹理渲染。即使画布与纹理的大小完全相同,WebGL 似乎也无法正确插入数据。
有人有提示吗?
提前致谢。