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 –
您確定第一個代碼段正確嗎?它包含兩對相同的座標。它不符合第二個代碼片段。 –