-
I was playing with the project's source code for better understanding, and when I replaced the let (texture_width, texture_height) = texture_size;
let (screen_width, screen_height) = screen_size;
let width_ratio = (screen_width / texture_width).max(1.0);
let height_ratio = (screen_height / texture_height).max(1.0);
// Get smallest scale size
let scale = width_ratio.clamp(1.0, height_ratio).floor();
let scaled_width = texture_width * scale;
let scaled_height = texture_height * scale;
// Create a transformation matrix
let sw = scaled_width / screen_width;
let sh = scaled_height / screen_height;
let tx = (screen_width / 2.0).fract() / screen_width;
let ty = (screen_height / 2.0).fract() / screen_height;
#[rustfmt::skip]
let transform: [f32; 16] = [
sw, 0.0, 0.0, 0.0,
0.0, sh, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
tx, ty, 0.0, 1.0,
]; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
The scaling matrix is for adding the border around the image when the surface is not an exact multiple of the image size. A good example is the screenshot used for the A better example is the Android screenshot: Without the border, the texture would be unnaturally stretched to fit the surface size. |
Beta Was this translation helpful? Give feedback.
Specifically,
tx
andty
are for translation. If the surface is an odd number of pixels in either direction, these variables will nudge the triangle by half a pixel so that the pixels in the triangle align with pixels on the physical screen.Without them, you would get an ugly half-pixel offset. See #231.