You can rotate the OpenGL output in the vertex shader as follows:
#version 300 es in vec4 position; in mediump vec4 texturecoordinate; in vec4 color; uniform float preferredRotation; out mediump vec2 coordinate; void main() { //const float pi = 4.0 * atan(1.0); //float radians = (( -90.0 ) / 180.0 * pi ); // Preferred rotation of video acquired, for example, by: // AVAssetTrack *videoTrack = [tracks objectAtIndex:0]; // CGAffineTransform preferredTransform = [videoTrack preferredTransform]; // self.glKitView.preferredRotation = -1 * atan2(preferredTransform.b, preferredTransform.a); // Preferred rotation for both portrait and landscape mat4 rotationMatrix = mat4( cos(preferredRotation), -sin(preferredRotation), 0.0, 0.0, sin(preferredRotation), cos(preferredRotation), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); // Mirror vertical (portrait only) mat4 rotationMatrix = mat4( cos(preferredRotation), sin(preferredRotation), 0.0, 0.0, -sin(preferredRotation), cos(preferredRotation), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); // Mirror horizontal (landscape only) mat4 rotationMatrix = mat4( 1.0, 0.0, 0.0, 0.0, 0.0, cos(preferredRotation), -sin(preferredRotation), 0.0, 0.0, sin(preferredRotation), cos(preferredRotation), 0.0, 0.0, 0.0, 0.0, 1.0); // Mirror vertical (landscape only) mat4 rotationMatrix = mat4( cos(preferredRotation), 0.0, sin(preferredRotation), 0.0, 0.0, 1.0, 0.0, 0.0, -sin(preferredRotation), 0.0, cos(preferredRotation), 0.0, 0.0, 0.0, 0.0, 1.0); gl_Position = position * rotationMatrix; coordinate = texturecoordinate.xy; }
With each vSync, you can pass a new value to preferredRotation, which will rotate the view without stretching.
Obviously, you select only one matrix4, depending on the orientation of the video, and then its rotation. Each matrix 4 flips the video window - does not rotate it. To rotate, you must first select the matrix4 based on the orientation, and then replace the preferredRotation variable with the number of degrees (in radians, a formula for which is also provided).
There are many ways to rotate a view, layer, object, etc .; but if you create an image through OpenGL, then you should choose this method and only this method.