Jump to content

Efficient method for playing a video as a texture


photo

Recommended Posts

Let's say I have a video I'd like to play on a quad. What is the most efficient / preferred way to update a texture based on the current video frame? The snippet below is the best I've come up with so far, but it feels like a hack and only works with OpenGL (D3D11 crashes with a deallocation error). Is there a better way?


Unigine::ImagePtr image = Unigine::Image::create();
Unigine::TexturePtr texture = material->getImageTexture(material->findTexture("diffuse"));
texture->create2D(width, height, Unigine::Image::FORMAT_RGB8);
texture->getImage(image);
while(play_video) {
	unsigned char* texData = ... //Load raw pixel data
	image->setPixels(texData);
	texture->setImage(texImage);
	//engine update/render/swap 
	...
}

//where setPixels is a function I added to the Image.{h,cpp} source:
void Image::setPixels(unsigned char *pixels) {
	data = pixels;
}

Link to comment
×
×
  • Create New...