2

对不起我的英语不好

我想显示文件中的视频,其中每像素 4 字节的帧,BRGA,1280x720?

在 mac 上,我只是取出框架并绘制了这个 glDrawPixels,在 Mac 上运行,但在 opengl es 中完全不同。

这是来自mac的代码

int pos = 0;
NSData *data = [[NSData alloc] initWithContentsOfFile:@"video.raw"];
glViewport(0,0,width,height);
glLoadIdentity();
glOrtho(0, width, 0, height, -1.0, 1.0);
glPixelZoom(1, -1);
glClear(GL_COLOR_BUFFER_BIT);
//glRasterPos2i(0, height);
glRasterPos2i(0, 0);
glDrawPixels(1280, 720, GL_BGRA, GL_UNSIGNED_BYTE, [data bytes]+pos);
glFinish();
4

1 回答 1

2

使用“glTexSubImage2D”将这些数据推送到纹理并渲染纹理。请注意,尽管纹理必须是 2 的幂,因此对于您的情况,您可以制作 (2048, 1024) 但您只能更新 (1280, 720) 部分:

CGSize videoSize;
CGSize textureSize;
GLuint dimension = 1;
while (videoSize.width > dimension) {
    dimension <<= 1;
}
textureSize = CGSizeMake(dimension, .0f);
dimension = 1;
while (videoSize.height > dimension) {
    dimension <<= 1;
}
textureSize = CGSizeMake(textureSize.width, dimension);

GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureSize.width, textureSize.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

GLfloat textureCoordinates[] = {
    .0f, .0f,
    .0f, videoSize.height/textureSize.height,
    videoSize.width/textureSize.width, .0f,
    videoSize.width/textureSize.width, videoSize.height/textureSize.height
};

要更新纹理:

void *data;
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, videoSize.width, videoSize.height, GL_RGBA, GL_UNSIGNED_BYTE, data);

然后画出你的纹理四边形。

于 2012-12-06T08:01:51.080 回答