Skip to content

Instantly share code, notes, and snippets.

@clooth
Created September 18, 2013 21:42
Show Gist options
  • Save clooth/6616169 to your computer and use it in GitHub Desktop.
Save clooth/6616169 to your computer and use it in GitHub Desktop.
/**
Loads a BMP image into a texture on the rendering device
@param file The BMP image file to load
@param renderer The renderer to load the texture onto
@return the loaded texture, or nullptr if something went wrong.
*/
SDL_Texture *loadTexture(const std::string &file, SDL_Renderer *renderer)
{
SDL_Surface *loadedImage = SDL_LoadBMP(file.c_str());
if (loadedImage == nullptr) {
logSDLError(std::cout, "LoadBMP");
return nullptr;
}
SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, loadedImage);
SDL_FreeSurface(loadedImage);
if (texture == nullptr) {
logSDLError(std::cout, "CreateTextureFromSurface");
return nullptr;
}
return texture;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment