SDL_Surface *FlipSurfaceV(SDL_Surface *bitmap){ if(!bitmap)return NULL; SDL_Surface *temp=SDL_CreateRGBSurface(0,bitmap->w,bitmap->h, bitmap->format->BitsPerPixel,bitmap->format->Rmask,bitmap->format->Gmask, bitmap->format->Bmask,bitmap->format->Amask); if(!temp)return NULL; unsigned int rowsize = bitmap->w*(bitmap->format->BitsPerPixel/8); char* src = (char*)bitmap->pixels; char* dest = ((char*)temp->pixels)+(temp->h-1)*rowsize; for(int i=0;i<bitmap->h;i++) { memcpy(dest, src, rowsize); src += rowsize; dest -= rowsize; } return temp;}
Then the following code loads the image and creates the texture:
string file = map.name; SDL_Surface* mm = IMG_Load(file.c_str()); SDL_Surface* m = FlipSurfaceV(mm); 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