Answer the question
In order to leave comments, you need to log in
How to keep texture aspect ratio in WebGL?
Hello, I have a little misunderstanding of working with webgl. I'm trying to load an image as a texture into a canvas. But it does not maintain proportions and has some disproportionate dimensions. Attempts to change various parameters did not lead to anything sensible. And how did I understand that the textures should be square, but what if not? How do I fit a texture into a canvas while maintaining aspect ratio?
Example
https://codepen.io/anon/pen/QZYboL
Answer the question
In order to leave comments, you need to log in
Judging by this example, the texture must have dimensions of a power of two (2, 4, 8, 16, 32, 64, etc.). If it does not match these dimensions, then the parameter is used CLAMP_TO_EDGE
, which stretches/crops the image to the nearest suitable size.
Again, they write on StackOverflow that if the browser supports WebGL 2.0, then there is a so-called. NPOT textures should be supported without issue - proof .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question