Created
September 18, 2013 21:42
-
-
Save clooth/6616169 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
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