Advertisement Jump to content
Sign in to follow this  

OpenGL SDL_ffmpeg with OpenGL

This topic is 3960 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm looking for an MPEG video playback library to use with my OpenGL engine, and since everything else in my project is SDL based I'd like to give SDL_ffmpeg a try. As with using SDL_image to load textures, and SDL_ttf to load fonts, I have to convert an SDL_surface to a GL texture for it to be of any use. I'm currently using the following for such operations:
GLuint SDL_Surface_To_GL_Tex(SDL_Surface *Surface)
		GLuint Texture;
		int Width, Height;
		SDL_Surface *Image;
		SDL_Rect Area;

		//Get the dimentions of the surface
		Area.x = 0;
		Area.y = 0;
		Area.w = Surface->w;
		Area.h = Surface->h;

		//Make sure the width and height are powers of two
		Width = NextPowerOfTwo(Surface->w);
		Height = NextPowerOfTwo(Surface->h);

		//Create an OpenGL compliant surface
		Image = SDL_CreateRGBSurface(SDL_SWSURFACE, Width, Height, 32, 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000);

		//Copy the surface to the OpenGL compatible one
		SDL_BlitSurface(Surface, &Area, Image, &Area);


		//Generate an OpenGL texture
		glGenTextures(1, &Texture);

		//Bind the texture ready for use
		glBindTexture(GL_TEXTURE_2D, Texture);

		//Copy data from the SDL surface to the OpenGL texture
		glTexImage2D(GL_TEXTURE_2D, 0, 4, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Image->pixels);

		//Set texture filtering


		//Free the SDL surface

		//Return the texture
		return Texture;

This would need to be done every frame for MPEG playback. Before I waste my time implementing a wrapper class for SDL_ffmpeg, is there a faster way to copy an SDL_surface to a GL compliant texture? I think the above would be borderline unacceptable as a realtime operation.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!