Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Store Width And Height In Texture Object #177

Open
fweth opened this issue Feb 3, 2021 · 1 comment
Open

Feature Request: Store Width And Height In Texture Object #177

fweth opened this issue Feb 3, 2021 · 1 comment

Comments

@fweth
Copy link

fweth commented Feb 3, 2021

When creating a texture from an image URL, it would be useful to have the width and height of the image stored in the returned texture object somewhere.

@greggman
Copy link
Owner

greggman commented Feb 3, 2021

The width and height of the texture are not available until after the texture has loaded but you're given a texture immediately after calling twgl.createTexture

You can write your own wrapper

function createTexture(gl, url) {
  const texture = twgl.createTexture(gl, url, (err, tex, img) => {
     texture.width = img.width;
     texture.height = img.height;
  });
  if (texture) {
    texture.width = texture.height = 1;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants