This won't work out of the box, and utilizes SDL_image to load the actual image for cross-platform compatibility. However, if you look over this code it should help you get the idea.
typedef struct { GLuint texture; int ow; // Old width int oh; // Old height int w; int h; char filename[32]; char type; char *bitmask;} GLtexture;GLtexture* OGL_S2T(char *filename){ Uint8 *rowhi, *rowlo; Uint8 *tmpbuf, tmpch; SDL_Surface *s; SDL_Surface *tmp; int i, j; int x2, y2; SDL_Color clr; Uint32 col = 0; Uint32 col2 = 0; char *gpos = NULL; char *hpos = NULL; int iw=0, ih=0; int exp = 1; GLtexture *tex = (GLtexture *)malloc(sizeof(GLtexture)); s = IMG_Load(filename); if ( s == NULL ) { fprintf(stderr, "Unable to load %s: %s\n", filename, SDL_GetError()); return(NULL); } SDL_DisplayFormatAlpha(s); tex->ow = s->w; tex->oh = s->h; while(pow(2, exp) < s->w) exp++; iw = pow(2, exp); exp = 1; while(pow(2, exp) < s->h) exp++; ih = pow(2, exp); tmp = SDL_CreateRGBSurface(SDL_HWSURFACE|SDL_SRCALPHA, iw, ih, 32, 0, 0, 0, 255); SDL_LockSurface(tmp); SDL_LockSurface(s); y2 = 0; while(y2 < s->h) { x2 = 0; while(x2 < s->w) { gpos = (char *)s->pixels; gpos += (s->pitch * y2); gpos += (s->format->BytesPerPixel * x2); hpos = (char*)tmp->pixels; hpos += (tmp->pitch *y2); hpos += (tmp->format->BytesPerPixel * x2); memcpy(&col, gpos, s->format->BytesPerPixel); SDL_GetRGBA(col, s->format, &clr.r, &clr.g, &clr.b, &clr.unused); col2 = SDL_MapRGBA(s->format, clr.r, clr.g, clr.b, clr.unused); memcpy(hpos, &col2, tmp->format->BytesPerPixel); x2++; } y2++; } SDL_UnlockSurface(tmp); SDL_UnlockSurface(s); tex->bitmask = GenBitMask(s); SDL_FreeSurface(s); /* GL surfaces are upsidedown and RGB, not BGR :-) */ tmpbuf = (Uint8 *)malloc(tmp->pitch); if ( tmpbuf == NULL ) { fprintf(stderr, "Out of memory\n"); return(NULL); } rowhi = (Uint8 *)tmp->pixels; rowlo = rowhi + (tmp->h * tmp->pitch) - tmp->pitch; for ( i=0; i<tmp->h/2; ++i ) { for ( j=0; j<tmp->w; ++j ) { tmpch = rowhi[j*4]; rowhi[j*4] = rowhi[j*4+2]; rowhi[j*4+2] = tmpch; tmpch = rowlo[j*4]; rowlo[j*4] = rowlo[j*4+2]; rowlo[j*4+2] = tmpch; } memcpy(tmpbuf, rowhi, tmp->pitch); memcpy(rowhi, rowlo, tmp->pitch); memcpy(rowlo, tmpbuf, tmp->pitch); rowhi += tmp->pitch; rowlo -= tmp->pitch; } free(tmpbuf); glGenTextures(1, &tex->texture); glBindTexture(GL_TEXTURE_2D, tex->texture); tex->w = iw; tex->h = ih; glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 4, iw, ih, 0, GL_BGRA, GL_UNSIGNED_BYTE, tmp->pixels); SDL_FreeSurface(tmp); strcpy(tex->filename, filename); tex->type = GFX_TYPE_BMP; return tex; }