greggman / twgl.js

A Tiny WebGL helper Library
http://twgljs.org
MIT License
2.67k stars 260 forks source link

Feature Request: Texture From SVG With Custom Dimensions #175

Open fweth opened 3 years ago

fweth commented 3 years ago

Hi, apparently width and height are only used in texture options when "src is an array or typed array or null." Would be cool if dimensions could als be specified for a cleanly scaled up SVG. What I do to achieve this manually is creating a canvas in the given dimensions, then use drawImage to draw SVG to canvas and then create the texture from the canvas, like this:

ctx = document.createElement("canvas").getContext("2d");
ctx.canvas.width = width;
ctx.canvas.height = height;
ctx.drawImage(img, 0, 0, width, height);
imgTx = twgl.createTexture(glCtx, { flipY: 1, src: ctx.canvas });