2

sorry for my english

I want to display video from a file, where the frames of 4 bytes per pixel, BRGA, 1280x720?

on mac I just took out the frame and drew this glDrawPixels, running on a Mac but in opengl es all differently.

here's the code from the 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();
user1881371
  • 129
  • 11

1 Answers1

2

Push those data to texture with "glTexSubImage2D" and render the texture. Note though that texture has to be of power of 2 so for your case you can make it (2048, 1024) but you may update only the (1280, 720) part:

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
};

To update the texture:

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

Then just draw your textured quad.

Matic Oblak
  • 16,318
  • 3
  • 24
  • 43
  • Yes, I tried both, I did not work, I'll try it! if possible code? – user1881371 Dec 06 '12 at 10:45
  • yes! this works! Thank you! is there any other ideas? faster than this render to texture, I tried it, but not yet earned – user1881371 Dec 07 '12 at 12:01
  • I never did try but it might be logical if video size was same as texture size it could push the data faster.. You could export your video files with power of 2 size and then control the width/height with vertex coordinates or scaling the matrix. Also at this point you might want to launch your time profiler to see what line is the most consuming one. – Matic Oblak Dec 07 '12 at 12:31
  • Tried this version - does not work, I think makes a mistake! If there is a working code - it will be easier, but still use what is, time is running out. But vernuts to render to texture – user1881371 Dec 07 '12 at 18:21