Sign in to follow this  

glBindTexture...SDL_Surface...?

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

To help me focus on 3d programming ive always used SDL_Surface to hold my texture objects, like this SDL_Surface *texture; ... texture = SDL_LoadBMP("sometexture.bmp"); Then i just use the glTexImage2d before the rendering, and i realize this is slow but im still learning. I am now trying to get further and optimize my code, so i tryed to use the glBindTexture, well, it doesnt really like me feeding it an sdl_surface, so i tryed turning the texture into a GLuint, but then the SDL_LoadBMP command gets cranky... How can use the sdl_loadbmp and be able to bind the texture it loads?

Share this post


Link to post
Share on other sites
This should work

        int LoadBmp(char* filename, GLuint* data)
{
SDL_Surface* bmpFile = SDL_LoadBMP(filename);

h = bmpFile->h;
w = bmpFile->w;

glPixelStorei(GL_UNPACK_ALIGNMENT,4);

glGenTextures(1,&data);
glBindTexture(GL_TEXTURE_2D,data);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

gluBuild2DMipmaps(GL_TEXTURE_2D,3,bmpFile->w, bmpFile->h,GL_BGR_EXT, GL_UNSIGNED_BYTE,bmpFile->pixels);

SDL_FreeSurface(bmpFile);

return 0;
}

Share this post


Link to post
Share on other sites

This topic is 4835 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this