Jump to content
  • Advertisement
Sign in to follow this  
Jonan

OpenGL Texture from SDL_image

This topic is 4488 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

Hello, I have a problem using OpenGl. The thing is that I want to create a texture from a SDL_Surface, I explain, I load an image with SDL_image into a SDL_Surface, and I need to create a texture for OpenGL from this SDL_Surface. The function I use to load the image is IMG_Load(). Can someone help me? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Loading a OpenGL texture with SDL_Surface data:

http://www.libsdl.org/cgi/docwiki.cgi/OpenGL_20Texture_20Example

Share this post


Link to post
Share on other sites
just some code if you find it useful:

SDL_Surface* mm = IMG_Load("texture.tga");
if(!mm) exit(0);
SDL_Surface* m = FlipSurfaceV(mm); //Reverse the pixels because using tga

unsigned int t;
glGenTextures(1, &t);
glBindTexture(GL_TEXTURE_2D, t);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m->w, m->h, 0, GL_BGRA, GL_UNSIGNED_BYTE, m->pixels);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // Linear Filtering



Should be everything clear. If you wonder what FlipSurfaceV() is, it's only a function I wrote to reorder the pixels in a tga image. If you use other formats, don't care about that. If you need it, just ask ;-)

Share this post


Link to post
Share on other sites
Thanks to everyone, I've been able to do it now. I don't use .tga, I only use .jpg, .png and .gif, so I have no problem.

Thanks again

Share this post


Link to post
Share on other sites
Good to hear that you solved your problem. Just remember that gif only stores up to 256 indexed colors and that jpg doesn't provide alpha channel...

Share this post


Link to post
Share on other sites
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!