Jump to content
  • Advertisement
Sign in to follow this  
deadstar

OpenGL SDL_ffmpeg with OpenGL

This topic is 3804 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);

		glEnable(GL_TEXTURE_2D);

		//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
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

		glDisable(GL_TEXTURE_2D);

		//Free the SDL surface
		SDL_FreeSurface(Image);

		//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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!