No texture bound to the unit 0

2019-09-21 11:04发布

I am currently facing an error that I cannot seem to figure out.

In chrome I am receiving:

GL ERROR :GL_INVALID_VALUE : glTexImage2D: invalid internal_format GL_FALSE
RENDER WARNING: there is no texture bound to the unit 0

Which is resulting in my 3D object having just a black texture rather than the image I have waiting to be rendered.

2条回答
我只想做你的唯一
2楼-- · 2019-09-21 11:38

So I found the answer after fiddling around with my code a little, turns out its a simple fix (maybe stupidity on my part) but what I used to have was this:

var boxTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, boxTexture);
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);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA,     gl.UNSIGNED_BYTE,document.getElementById('crate-image'));
gl.bindTexture(gl.TEXTURE_2D, null);

All that needed changing was the order, so now it looks like this:

var boxTexture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, boxTexture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
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);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA,     gl.UNSIGNED_BYTE,document.getElementById('crate-image'));
gl.bindTexture(gl.TEXTURE_2D, null);
查看更多
Emotional °昔
3楼-- · 2019-09-21 11:40

internal_format is the 3rd argument to gl.texImage2D. The error mesages says you are passing either 0 or undefined or null. All of those become 0 which is the same as GL_FALSE.

You need to pass a valid internal format like gl.RGBA, gl.RGB, etc...

The second error is because of the first.

查看更多
登录 后发表回答