0
我必须裁剪视频。openGL es 2.0 TextureCoordinates参数ios
所以我修改TextureCoordinates。
代码如下。
const GLfloat squareTextureCoordinates[] = {
0.22f , 1.0f,
0.22f, 0.0f,
0.78f, 1.0f,
0.78f, 0.0f,
};
glVertexAttribPointer(positionAttribute, 2, GL_FLOAT, 0, 0, squareVertices);
glVertexAttribPointer(inputTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, squareTextureCoordinates);
此代码是工作。
但是,我需要支持多种尺寸的iphone(例如:iphone6与iphone5有不同的尺寸) 所以我在TextureCoordinates中使用变量而不是const。 新代码如下所示;
const float cropX=(float)(SCREEN_HEIGHT-SCREEN_WIDTH)/(float)(SCREEN_HEIGHT*2);
const float cropXR=1- (float)(SCREEN_HEIGHT-SCREEN_WIDTH)/(float)(SCREEN_HEIGHT*2);
const GLfloat squareTextureCoordinates[] = {
cropX , 1.0f,
cropX, 0.0f,
cropXR, 1.0f,
cropXR, 0.0f,
};
glVertexAttribPointer(positionAttribute, 2, GL_FLOAT, 0, 0, squareVertices);
glVertexAttribPointer(inputTextureCoordinateAttribute, 2, GL_FLOAT, 0, 0, squareTextureCoordinates);
但是,它不起作用。 屏幕无显示。
我不知道为什么我不能使用const变量为TextureCoordinates。
你能说明'SCREEN_WIDTH'和'SCREEN_HEIGHT'是如何定义的吗? –
当然,这是#define SCREEN_WIDTH [[UIScreen mainScreen]范围] .size.width –
您确定第一个代码段正确吗?它包含两对相同的坐标。它不符合第二个代码片段。 –