26360

opengl es(iphone) render from file

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();

Answer1:

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.

Recommend

  • Drift in rotation about z-axis
  • Cut QGLWidget?
  • CMake linking glfw3 lib error
  • How create UIImage from bytes?
  • Error Domain=NSCocoaErrorDomain Code=3840 “Invalid value around character 0.” UserInfo={NSDebugDescr
  • C++ how to get substring after get position of its index
  • Position Fixed in Chrome
  • jParallax trouble
  • How to get a table cell value using jQuery
  • Updating one element of a bound Observable collection
  • Laravel lmutator $this->attributes return 'Undefined index: id'
  • How to set an entity field that does not exist on the table but does exists in the raw SQL as an ali
  • How to remove all of a jQuery UI dialog when it is closed
  • Parenthesis() and SQL Query Performance
  • Responsive Form on top of Responsive Image? - Bootstrap
  • Count from each distinct date, fill in missing dates with zero
  • jQuery - resize an elements height to match window without refreshing, on window resize
  • Flex items with same property values are rendering in different sizes
  • Using Generics on right hand side in Java 6?
  • chrome video src change not working
  • WPF Template Binding in ToggleButton UserControl
  • blade.php method outputting it's result to the form
  • Floated image with variable width and heading with background image
  • Subclassing QGraphicsItem prevents me from being able to use itemAt() on a QGraphicsScene/View
  • Can't delete or rename original file after resizing
  • D3 get axis values on zoom event
  • NSScanner Loop Question
  • Connect .sks to skscene.h
  • OpenGL 3.3 on Mac OSX El Capitan with LWJGL
  • How to set/get protobuf's extension field in Go?
  • How to show dropdown in excel using jrxml (jasper api)?
  • Eraser for UIBezierPath
  • align graphs with different xlab
  • Compare two NSDates in iPhone
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • python draw pie shapes with colour filled
  • How to get NHibernate ISession to cache entity not retrieved by primary key
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app