Texture from SDL_image
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
Loading a OpenGL texture with SDL_Surface data:
http://www.libsdl.org/cgi/docwiki.cgi/OpenGL_20Texture_20Example
http://www.libsdl.org/cgi/docwiki.cgi/OpenGL_20Texture_20Example
just some code if you find it useful:
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 ;-)
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 ;-)
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
Thanks again
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...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement