Code: Select all
SDL_Surface *Img::GetPaddedImage(SDL_Surface *image, Rect rect){
// Generate a padded image using the given one
SDL_Surface *temp = SDL_CreateRGBSurface(SDL_SWSURFACE, (int)rect.Width(), (int)rect.Height(), image->format->BitsPerPixel,
image->format->Rmask, image->format->Gmask,
image->format->Bmask, image->format->Amask);
SDL_FillRect(temp, NULL, 0xFF00FF);
SDL_BlitSurface(image, NULL, temp, NULL);
return temp;
}
The code above just results in a blank image with no channels being rendered.
For the purposes of showing how textures are created (just in case), heres my Texture generation code:
Code: Select all
void Texture2D::Gen(SDL_Surface *sur){
// Generate the texture using the image given
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
GLenum texFormat = GL_RGBA; // Format used for the texture
// Make sure the dimensions are of power of two
if (!isPowerOfTwo(sur->w) || !isPowerOfTwo(sur->h)){
pad.SetSize((float)sur->w, (float)sur->h);
padded = true;
sur = Img::GetPaddedImage(sur, Rect(0.0f, 0.0f,
(float)NextPowerOfTwo(sur->w),
(float)NextPowerOfTwo(sur->h)));
}
// Decide which format to use
if (sur->format->BytesPerPixel == 4){
texFormat = GL_RGBA;
} else if (sur->format->BytesPerPixel == 3){
texFormat = GL_RGB;
}
// Create the texture
glTexImage2D(GL_TEXTURE_2D, 0, 4, sur->w, sur->h,
0, texFormat, GL_UNSIGNED_BYTE, sur->pixels);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
// Get the sizes of the texture
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &texWidth);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &texHeight);
DebugSys::Inst()->DebugAsset(this);
}