How to scale a texture in webgl?
问题 I have a texture of size 800x600. How do I scale it on a webgl <canvas> at another size and keep the original aspect ratio? Assuming that the drawing buffer and the canvas have the same dimensions. 回答1: Given the WebGL only cares about clipsapce coordinates you can just draw a 2 unit quad (-1 to +1) and scale it by the aspect of the canvas vs the aspect of the image. In other words const canvasAspect = canvas.clientWidth / canvas.clientHeight; const imageAspect = image.width / image.height;