Skip to main content
gamedev.net
🔒 Locked

Texture from SDL_image

Started by Jonan Jul 3, 2006 at 1:40 PM 5 replies 1.1k views
Original Post
Jonan
Jonan
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
JohnnyCasil
JohnnyCasil
Just pass the info needed from the SDL_Surface* structure to glTexImage2D.
Taymo
Taymo
Loading a OpenGL texture with SDL_Surface data:

http://www.libsdl.org/cgi/docwiki.cgi/OpenGL_20Texture_20Example
Dev Journal - Ride the Spiralhttp://spiralride.blogspot.com/
cignox1
cignox1
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 ;-)
Jonan
Jonan
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
cignox1
cignox1
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...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.