Couldn't create Texture from resized DOM Image
See original GitHub issueDescribe the bug
If the DOM image is resized with CSS, like: width: 10%
, and you try to create texture with THREE.Texture(DOM_ELEMENT) class, that will result in:
GL ERROR :GL_INVALID_VALUE : glTexSubImage2D: bad dimensions.
The behaviour appears since v135. It is not present in v134.
To Reproduce
Steps to reproduce the behavior:
- Create a DOM image in HTML
- Resize it with CSS: img{width: 10%}
- Create a texture from image with THREE.Texture(DomElement) class
- Use texture on any material
- You will get: GL ERROR :GL_INVALID_VALUE : glTexSubImage2D: bad dimensions. in latest Chrome.
Code
let material = new THREE.MeshBasicMaterial();
let img = document.querySelector('img')
let texture = new THREE.Texture(img)
texture.needsUpdate = true;
material.map = texture;
mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
Live example
- ~jsfiddle-latest-release (forgot to set display:block here, hence new demo)~
- bug
Expected behavior
To see sphere with kitten texture.
Screenshots
This is the expected result of demo.
Platform:
- Device: Desktop
- OS: MacOs
- Browser: Chrome
- Three.js version: r136
Issue Analytics
- State:
- Created 2 years ago
- Comments:24 (3 by maintainers)
Top Results From Across the Web
GL_INVALID_VALUE: Offset overflows texture dimensions
Couldn't create Texture from resized DOM Image ... You potentially have to update your GLSL since the shader always uses the natural dimensions...
Read more >three js, WebGLRenderer image quality drops on safari
WebGLRenderer: Texture has been resized from (4000x2000) to (2048x1024). camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.
Read more >Engine Error: Couldn't create Texture/Shader - 887a005 Error
I took the game files for Apex Legends from my mate and after playing for a day, I got the "Cannot create texture"...
Read more >Image Textures
All this is done on the JavaScript side. The command for creating a texture object is gl.createTexture(). The command in OpenGL 1.1 was...
Read more >melonjs/public - Gitter
I've been trying to make it work for hours, but I just couldn't ... You need to use a canvas context, or an...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, so, instead of
I used this workaround:
also in one case this:
But of course, would be perfect to fix issue, to not do this. Or is it best practice now to clone everything from DOM before converting it to texture? 🤔
could asking other developers on discord be a way to make up a decision? For me as one of three.js dev-users it is obvious that i expect three.js to disregard any CSS, when i convert DOM element to WebGL Texture. And my hypothesis is its like that for 99% people. Because those are two different mental models/concepts/coordinate-systems, and i dont want them to interfere.
What are the possible drawbacks of using naturalWidth here?