Opengl es (iphone) rendering from file

sorry for my English

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

on mac I just pulled out a frame and drew this glDrawPixels running on Mac, but in opengl es it's different.

here is the code from 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(); 
+2
source share
1 answer

Click this data on the texture with "glTexSubImage2D" and render the texture. Please note that this texture should have a power of 2, so for your business you can do this (2048, 1024), but you can only update the part (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 }; 

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 box.

+2
source

All Articles