I am trying to use GLSL to rotate an image (via glfx.js).
I have checked prior answers such as this and this but the results are still a skewed picture (first answer), or the answer is a bit too terse for my beginner level (the second).
The fragment shader I use looks like this:
uniform sampler2D texture;
uniform vec2 texSize;
varying vec2 texCoord;
uniform float degrees;
const float PI = 3.1415926535897932384626433832795;
float deg2rad(float deg){ return deg * PI / 180.0; }
void main() {
vec2 coord = texCoord.xy;
float sin_factor = sin(deg2rad(degrees));
float cos_factor = cos(deg2rad(degrees));
coord = coord * mat2(cos_factor, sin_factor, -sin_factor, cos_factor);
coord = vec2(mod(coord.x, 1.0), mod(coord.y, 1.0));
vec4 color = texture2D(texture, coord);
float grey = 0.299 * color.r + 0.587 * color.g + 0.114 * color.b;
gl_FragColor = vec4(color);
However the resulting image (webcam shot of my ceiling) rotated by 30 degrees is skewed, and when rotated by 180 it is flipped around the X axis, but not the Y (i.e.: it is mirrored).
What do I need to fix so that the image is not skewed or flipped?