如下您可以旋转的顶点着色器OpenGL的输出:
#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;
}
对于每个垂直同步,你可以通过对preferredRotation一个新值,这将旋转视图不拉伸。
显然,您只选择一个矩阵4,具体取决于视频的方向,然后根据视频的旋转方向。每个矩阵4翻转视频窗口 - 不旋转它。对于旋转,您必须首先根据方向选择矩阵4,然后将preferredRotation变量替换为度数(以弧度表示,也提供了公式)。
有很多方法可以旋转视图,图层,对象等;但是,如果你通过OpenGL渲染图像,那么你应该选择这种方法,并且只能使用这种方法。
OK我想我理解我的问题的答案的一部分,即我需要在方向更改期间继续呈现呈现缓冲区,以覆盖默认情况下显示的内容。目前,只有在需要根据用户界面更改更改视图内容时,才会显示它。 – Robotbugs 2013-02-28 00:48:22