├── App.cpp ├── App.h ├── FileManager.cpp ├── FileManager.h ├── Log.h ├── README ├── Stringify.cpp ├── Stringify.h ├── Texture.cpp ├── Texture.h ├── TextureBank.cpp ├── TextureBank.h ├── main.cpp └── sdl-2.0-textures.cbp /App.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | #include "App.h" 3 | #include "Log.h" 4 | 5 | App App::Instance; 6 | 7 | //============================================================================== 8 | App::App() { 9 | } 10 | 11 | //------------------------------------------------------------------------------ 12 | void App::OnEvent(SDL_Event* Event) { 13 | } 14 | 15 | //------------------------------------------------------------------------------ 16 | bool App::Init() { 17 | if(SDL_Init(SDL_INIT_VIDEO) < 0) { 18 | Log("Unable to Init SDL: %s", SDL_GetError()); 19 | return false; 20 | } 21 | 22 | if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) { 23 | Log("Unable to Init hinting: %s", SDL_GetError()); 24 | } 25 | 26 | if((Window = SDL_CreateWindow( 27 | "My SDL Game", 28 | SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 29 | WindowWidth, WindowHeight, SDL_WINDOW_SHOWN) 30 | ) == NULL) { 31 | Log("Unable to create SDL Window: %s", SDL_GetError()); 32 | return false; 33 | } 34 | 35 | PrimarySurface = SDL_GetWindowSurface(Window); 36 | 37 | if((Renderer = SDL_CreateRenderer(Window, -1, SDL_RENDERER_ACCELERATED)) == NULL) { 38 | Log("Unable to create renderer"); 39 | return false; 40 | } 41 | 42 | SDL_SetRenderDrawColor(Renderer, 0x00, 0x00, 0x00, 0xFF); 43 | 44 | // Initialize image loading for PNGs 45 | if(!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)) { 46 | Log("Unable to init SDL_image: %s", IMG_GetError()); 47 | return false; 48 | } 49 | 50 | // Load all of our Textures (see TextureBank class for expected folder) 51 | if(TextureBank::Init() == false) { 52 | Log("Unable to init TextureBank"); 53 | return false; 54 | } 55 | 56 | return true; 57 | } 58 | 59 | //------------------------------------------------------------------------------ 60 | void App::Loop() { 61 | } 62 | 63 | //------------------------------------------------------------------------------ 64 | void App::Render() { 65 | SDL_RenderClear(Renderer); 66 | 67 | TextureBank::Get("Test")->Render(0, 0); // You should really check your pointers 68 | 69 | SDL_RenderPresent(Renderer); 70 | } 71 | 72 | //------------------------------------------------------------------------------ 73 | void App::Cleanup() { 74 | TextureBank::Cleanup(); 75 | 76 | if(Renderer) { 77 | SDL_DestroyRenderer(Renderer); 78 | Renderer = NULL; 79 | } 80 | 81 | if(Window) { 82 | SDL_DestroyWindow(Window); 83 | Window = NULL; 84 | } 85 | 86 | IMG_Quit(); 87 | SDL_Quit(); 88 | } 89 | 90 | //------------------------------------------------------------------------------ 91 | int App::Execute(int argc, char* argv[]) { 92 | if(!Init()) return 0; 93 | 94 | SDL_Event Event; 95 | 96 | while(Running) { 97 | while(SDL_PollEvent(&Event) != 0) { 98 | OnEvent(&Event); 99 | 100 | if(Event.type == SDL_QUIT) Running = false; 101 | } 102 | 103 | Loop(); 104 | Render(); 105 | 106 | SDL_Delay(1); // Breath 107 | } 108 | 109 | Cleanup(); 110 | 111 | return 1; 112 | } 113 | 114 | //============================================================================== 115 | SDL_Renderer* App::GetRenderer() { return Renderer; } 116 | 117 | //============================================================================== 118 | App* App::GetInstance() { return &App::Instance; } 119 | 120 | int App::GetWindowWidth() { return WindowWidth; } 121 | int App::GetWindowHeight() { return WindowHeight; } 122 | 123 | //============================================================================== 124 | -------------------------------------------------------------------------------- /App.h: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | /* 3 | Primary application class 4 | 5 | 3/11/2014 6 | SDLTutorials.com 7 | Tim Jones 8 | */ 9 | //============================================================================== 10 | #ifndef __APP_H__ 11 | #define __APP_H__ 12 | 13 | #include 14 | 15 | #include "TextureBank.h" 16 | 17 | class App { 18 | private: 19 | static App Instance; 20 | 21 | bool Running = true; 22 | 23 | SDL_Window* Window = NULL; 24 | SDL_Renderer* Renderer = NULL; 25 | SDL_Surface* PrimarySurface = NULL; 26 | 27 | static const int WindowWidth = 1024; 28 | static const int WindowHeight = 768; 29 | 30 | Texture* TestTexture; 31 | 32 | private: 33 | App(); 34 | 35 | // Capture SDL Events 36 | void OnEvent(SDL_Event* Event); 37 | 38 | // Initialize our SDL game / app 39 | bool Init(); 40 | 41 | // Logic loop 42 | void Loop(); 43 | 44 | // Render loop (draw) 45 | void Render(); 46 | 47 | // Free up resources 48 | void Cleanup(); 49 | 50 | public: 51 | int Execute(int argc, char* argv[]); 52 | 53 | public: 54 | SDL_Renderer* GetRenderer(); 55 | 56 | public: 57 | static App* GetInstance(); 58 | 59 | static int GetWindowWidth(); 60 | static int GetWindowHeight(); 61 | }; 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /FileManager.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================= 2 | #include "FileManager.h" 3 | #include "Log.h" 4 | #include "Stringify.h" 5 | 6 | #ifndef _WIN32 7 | #include 8 | #include 9 | #else 10 | #include 11 | #endif 12 | #include 13 | 14 | //============================================================================= 15 | bool FileManager::SetContents(std::string Filename, std::string Content, bool Relative) { 16 | if(Filename == "") return false; 17 | 18 | if(Relative) Filename = GetCWD() + DIR_SEPARATOR + Filename; 19 | 20 | std::ofstream FileHandle; 21 | 22 | FileHandle.open(Filename.c_str()); 23 | if(!FileHandle.is_open()) return false; 24 | 25 | FileHandle << Content; 26 | FileHandle.close(); 27 | 28 | return true; 29 | } 30 | 31 | //----------------------------------------------------------------------------- 32 | std::string FileManager::GetContents(std::string Filename, bool Relative) { 33 | if(Filename == "") return ""; 34 | 35 | if(Relative) Filename = GetCWD() + DIR_SEPARATOR + Filename; 36 | 37 | std::string Content; 38 | std::ifstream FileHandle; 39 | 40 | FileHandle.open(Filename.c_str()); 41 | 42 | if(FileHandle.is_open()) { 43 | while(FileHandle.good()) { 44 | std::string Buffer; 45 | getline(FileHandle, Buffer); 46 | if(Buffer == "") continue; 47 | 48 | Content += Buffer + "\n"; 49 | } 50 | 51 | FileHandle.close(); 52 | } 53 | 54 | return Content; 55 | } 56 | 57 | //----------------------------------------------------------------------------- 58 | std::vector FileManager::GetFilesInFolder(std::string Folder) { 59 | std::vector List; 60 | 61 | std::string CWD = GetCWD(); 62 | std::string Path = CWD; 63 | 64 | if(Folder != "") Path += DIR_SEPARATOR + Folder; 65 | 66 | #ifdef __APPLE__ 67 | NSError* Error; 68 | 69 | NSString* PathNS = [NSString stringWithUTF8String:Path.c_str()]; 70 | NSArray* DirectoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:PathNS error:&Error]; 71 | 72 | for(id File in DirectoryContents) { 73 | std::string Filename = Path + DIR_SEPARATOR + [File cStringUsingEncoding:1]; 74 | 75 | List.push_back(Filename); 76 | } 77 | #elif _WIN32 78 | HANDLE dirHandle = NULL; 79 | WIN32_FIND_DATA FileHandle; 80 | std::string winPath(Path + DIR_SEPARATOR + std::string("*")); 81 | if ((dirHandle = FindFirstFile(winPath.c_str(), &FileHandle)) != INVALID_HANDLE_VALUE) 82 | { 83 | do 84 | { 85 | if (std::string(FileHandle.cFileName) == ".") continue; 86 | if (std::string(FileHandle.cFileName) == "..") continue; 87 | 88 | std::string Filename = Path + DIR_SEPARATOR + FileHandle.cFileName; 89 | 90 | List.push_back(Filename); 91 | } while (FindNextFile(dirHandle, &FileHandle) != false); 92 | FindClose(dirHandle); 93 | } 94 | else 95 | { 96 | Log("Unable to open directory: %s", Path.c_str()); 97 | } 98 | #else 99 | DIR* DirHandle = NULL; 100 | dirent* FileHandle = NULL; 101 | 102 | // Needs improved 103 | if((DirHandle = opendir(Folder.c_str())) != NULL) { 104 | while((FileHandle = readdir(DirHandle)) != NULL) { 105 | if(std::string(FileHandle->d_name) == ".") continue; 106 | if(std::string(FileHandle->d_name) == "..") continue; 107 | 108 | std::string Filename = Path + DIR_SEPARATOR + FileHandle->d_name; 109 | 110 | //Log("Found File: %s", Filename.c_str()); 111 | 112 | List.push_back(Filename); 113 | } 114 | 115 | closedir(DirHandle); 116 | }else{ 117 | Log("Unable to open directory : %s", Path.c_str()); 118 | } 119 | #endif 120 | 121 | return List; 122 | } 123 | 124 | //----------------------------------------------------------------------------- 125 | std::string FileManager::GetCWD() { 126 | std::string CWD; 127 | 128 | #ifdef __APPLE__ 129 | NSString* ResourcePath = [[NSBundle mainBundle] resourcePath]; 130 | CWD = [ResourcePath cStringUsingEncoding:1]; 131 | #elif defined(_WIN32) 132 | char buffer[MAX_PATH]; 133 | CWD = ((GetCurrentDirectory(MAX_PATH, buffer) > 0) ? std::string(buffer) : std::string("")); 134 | #else 135 | char Buffer[MAXPATHLEN]; 136 | CWD = (getcwd(Buffer, MAXPATHLEN) ? std::string(Buffer) : std::string("")); 137 | #endif 138 | 139 | return CWD; 140 | } 141 | 142 | //----------------------------------------------------------------------------- 143 | std::string FileManager::GetFilenameWithoutExt(std::string Filename) { 144 | std::vector Parts = Stringify::Explode(Filename, DIR_SEPARATOR); 145 | std::string NewFilename = Parts[Parts.size() - 1]; 146 | 147 | // To Do: Filename could potentially have one or more dots 148 | Parts = Stringify::Explode(NewFilename, "."); 149 | NewFilename = Parts[0]; 150 | 151 | return NewFilename; 152 | } 153 | 154 | //----------------------------------------------------------------------------- 155 | std::string FileManager::GetFilenameExt(std::string Filename) { 156 | std::vector Parts = Stringify::Explode(Filename, "."); 157 | 158 | return (Parts.size() <= 1 ? "" : Parts[Parts.size() - 1]); 159 | } 160 | 161 | //============================================================================= 162 | -------------------------------------------------------------------------------- /FileManager.h: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | /* 3 | Class for loading files and reading directories 4 | 5 | Note: To use iOS functions, set your file type to Objective-C++ 6 | 7 | 3/18/2014 8 | SDLTutorials.com 9 | Tim Jones 10 | */ 11 | //============================================================================== 12 | #ifndef __FILEMANAGER_H__ 13 | #define __FILEMANAGER_H__ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #define DIR_SEPARATOR "/" 22 | 23 | class FileManager { 24 | public: 25 | static bool SetContents(std::string Filename, std::string Content, bool Relative = true); 26 | 27 | static std::string GetContents(std::string Filename, bool Relative = true); 28 | 29 | static std::vector GetFilesInFolder(std::string Folder); 30 | 31 | static std::string GetCWD(); 32 | 33 | static std::string GetFilenameWithoutExt(std::string Filename); 34 | 35 | static std::string GetFilenameExt(std::string Filename); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Log.h: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | /* 3 | Basic macro for logging (can be extended for other target builds; i.e, using 4 | NSLog for OS X / iOS). Could also be modified to log to a file instead of 5 | console. 6 | 7 | 3/11/2014 8 | SDLTutorials.com 9 | Tim Jones 10 | */ 11 | //============================================================================== 12 | #ifndef __LOG_H__ 13 | #define __LOG_H__ 14 | 15 | #include 16 | 17 | #define DEBUG 1 18 | 19 | #ifdef DEBUG 20 | #define Log(...) printf(__VA_ARGS__); printf("\n"); 21 | #else 22 | #define Log(...) ; 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | SDL 2.0 Textures 2 | 3/18/2014 3 | 4 | Wraps SDL Textures into a more streamlined Texture class for easy loading and rendering. Also includes TextureBank class for loading multiple textures at once, and a FileManager class for reading directories (with iOS support). 5 | 6 | Build requirements 7 | - SDL 2.0 (http://libsdl.org/download-2.0.php) 8 | - SDL Image 2.0 (https://www.libsdl.org/projects/SDL_image/) 9 | 10 | Notes: 11 | - You probably want to use and build against 32-bit build of SDL 12 | - These project files assume SDL and SDL_image are located inside of "SDL2" folder and part of your search paths (SDL2/SDL.h) 13 | - Build files using a compatible c++11 compiler 14 | 15 | This tutorial and code are property of: 16 | Tim Jones 17 | SDLTutorials.com 18 | 19 | You are free to use this code and any included files in your projects (commercial and non-commercial), as long as you credit SDLTutorials.com and the author. 20 | -------------------------------------------------------------------------------- /Stringify.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | #include "Stringify.h" 3 | 4 | //============================================================================== 5 | std::string Stringify::Int(int x) { 6 | std::ostringstream o; 7 | 8 | o << x; 9 | 10 | return o.str(); 11 | } 12 | 13 | //------------------------------------------------------------------------------ 14 | std::string Stringify::Char(char* x) { 15 | std::string o = x; 16 | 17 | return o; 18 | } 19 | 20 | //------------------------------------------------------------------------------ 21 | std::string Stringify::Float(float x) { 22 | std::ostringstream o; 23 | 24 | o << x; 25 | 26 | return o.str(); 27 | } 28 | 29 | //------------------------------------------------------------------------------ 30 | std::string Stringify::Double(double x) { 31 | std::ostringstream o; 32 | 33 | o << x; 34 | 35 | return o.str(); 36 | } 37 | 38 | //============================================================================== 39 | int Stringify::ToInt(const std::string& String) { 40 | if(String == "") return 0; 41 | 42 | int X; 43 | std::stringstream strStream(String); 44 | 45 | strStream >> X; 46 | 47 | return X; 48 | } 49 | 50 | //------------------------------------------------------------------------------ 51 | float Stringify::ToFloat(const std::string& String) { 52 | if(String == "") return 0; 53 | 54 | float X; 55 | std::stringstream strStream(String); 56 | 57 | strStream >> X; 58 | 59 | return X; 60 | } 61 | 62 | //------------------------------------------------------------------------------ 63 | double Stringify::ToDouble(const std::string& String) { 64 | if(String == "") return 0; 65 | 66 | double X; 67 | std::stringstream strStream(String); 68 | 69 | strStream >> X; 70 | 71 | return X; 72 | } 73 | 74 | //============================================================================== 75 | //http://www.infernodevelopment.com/perfect-c-string-explode-split 76 | std::vector Stringify::Explode(std::string str, const std::string& separator) { 77 | std::vector Results; 78 | 79 | int found; 80 | found = str.find_first_of(separator); 81 | while(found != std::string::npos){ 82 | if(found > 0){ 83 | Results.push_back(str.substr(0,found)); 84 | } 85 | 86 | str = str.substr(found+1); 87 | found = str.find_first_of(separator); 88 | } 89 | 90 | if(str.length() > 0){ 91 | Results.push_back(str); 92 | } 93 | 94 | return Results; 95 | } 96 | 97 | //============================================================================== 98 | -------------------------------------------------------------------------------- /Stringify.h: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | /* 3 | Utility class for converting to and from strings 4 | 5 | 3/18/2014 6 | SDLTutorials.com 7 | Tim Jones 8 | */ 9 | //============================================================================== 10 | #ifndef _STRINGIFY_H_ 11 | #define _STRINGIFY_H_ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | class Stringify { 19 | public: 20 | static std::string Int(int x); 21 | static std::string Char(char* x); 22 | static std::string Float(float x); 23 | static std::string Double(double x); 24 | 25 | static int ToInt(const std::string& String); 26 | static float ToFloat(const std::string& String); 27 | static double ToDouble(const std::string& String); 28 | 29 | static std::vector Explode(std::string str, const std::string& separator); 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /Texture.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | #include "Texture.h" 3 | #include "Log.h" 4 | 5 | //============================================================================== 6 | Texture::Texture() { 7 | } 8 | 9 | //------------------------------------------------------------------------------ 10 | Texture::~Texture() { 11 | if(SDLTexture) { 12 | SDL_DestroyTexture(SDLTexture); 13 | SDLTexture = NULL; 14 | } 15 | } 16 | 17 | //============================================================================== 18 | bool Texture::Load(SDL_Renderer* Renderer, std::string Filename) { 19 | if(Renderer == NULL) { 20 | Log("Bad SDL renderer passed"); 21 | return false; 22 | } 23 | 24 | this->Renderer = Renderer; 25 | this->Filename = Filename; 26 | 27 | SDL_Surface* TempSurface = IMG_Load(Filename.c_str()); 28 | if(TempSurface == NULL) { 29 | Log("Unable to load image : %s : %s", Filename.c_str(), IMG_GetError()); 30 | return false; 31 | } 32 | 33 | // Convert SDL surface to a texture 34 | if((SDLTexture = SDL_CreateTextureFromSurface(Renderer, TempSurface)) == NULL) { 35 | Log("Unable to create SDL Texture : %s : %s", Filename.c_str(), IMG_GetError()); 36 | return false; 37 | } 38 | 39 | // Grab dimensions 40 | SDL_QueryTexture(SDLTexture, NULL, NULL, &Width, &Height); 41 | 42 | //Log("Texture Dimensions: %s : %d %d", Filename.c_str(), Width, Height); 43 | 44 | SDL_FreeSurface(TempSurface); 45 | 46 | return true; 47 | } 48 | 49 | //------------------------------------------------------------------------------ 50 | void Texture::Render(int X, int Y) { 51 | Render(X, Y, Width, Height); 52 | } 53 | 54 | //------------------------------------------------------------------------------ 55 | void Texture::Render(int X, int Y, int Width, int Height) { 56 | SDL_Rect Destination = {X, Y, Width, Height}; 57 | 58 | SDL_RenderCopy(Renderer, SDLTexture, NULL, &Destination); 59 | } 60 | 61 | //------------------------------------------------------------------------------ 62 | void Texture::Render(int X, int Y, int Width, int Height, int SX, int SY, int SWidth, int SHeight) { 63 | SDL_Rect Source = {SX, SY, SWidth, SHeight}; 64 | SDL_Rect Destination = {X, Y, Width, Height}; 65 | 66 | SDL_RenderCopy(Renderer, SDLTexture, &Source, &Destination); 67 | } 68 | 69 | //------------------------------------------------------------------------------ 70 | int Texture::GetWidth() { return Width; } 71 | int Texture::GetHeight() { return Height; } 72 | 73 | //============================================================================== 74 | -------------------------------------------------------------------------------- /Texture.h: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | /* 3 | Texture class for wrapping SDL Textures 4 | 5 | 3/13/2014 6 | SDLTutorials.com 7 | Tim Jones 8 | */ 9 | //============================================================================== 10 | #ifndef __TEXTURE_H__ 11 | #define __TEXTURE_H__ 12 | 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | class Texture { 19 | private: 20 | std::string Filename; 21 | 22 | int Width = 0; 23 | int Height = 0; 24 | 25 | SDL_Renderer* Renderer = NULL; 26 | SDL_Texture* SDLTexture = NULL; 27 | 28 | public: 29 | Texture(); 30 | ~Texture(); 31 | 32 | bool Load(SDL_Renderer* Renderer, std::string Filename); 33 | 34 | void Render(int X, int Y); 35 | 36 | void Render(int X, int Y, int Width, int Height); 37 | 38 | void Render(int X, int Y, int Width, int Height, int SX, int SY, int SWidth, int SHeight); 39 | 40 | int GetWidth(); 41 | int GetHeight(); 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /TextureBank.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================= 2 | #include "TextureBank.h" 3 | #include "App.h" 4 | #include "FileManager.h" 5 | #include "Log.h" 6 | 7 | //============================================================================= 8 | std::map TextureBank::TexList; 9 | 10 | //============================================================================= 11 | bool TextureBank::Init() { 12 | Cleanup(); 13 | 14 | SDL_Renderer* Renderer = App::GetInstance()->GetRenderer(); 15 | if(!Renderer) return false; 16 | 17 | std::vector Files = FileManager::GetFilesInFolder("Textures"); // Relative to CWD 18 | 19 | for(auto Filename : Files) { 20 | std::string Ext = FileManager::GetFilenameExt(Filename); 21 | std::string ID = FileManager::GetFilenameWithoutExt(Filename); 22 | 23 | // Skip all non-png files 24 | if(Ext != "png") continue; 25 | 26 | //Log("Add Texture : ID = %s : Filename = %s : Ext = %s", ID.c_str(), Filename.c_str(), Ext.c_str()); 27 | AddTexture(Renderer, ID, Filename); 28 | } 29 | 30 | return true; 31 | } 32 | 33 | //----------------------------------------------------------------------------- 34 | void TextureBank::Cleanup() { 35 | if(TexList.size() <= 0) return; 36 | 37 | for(auto& Iterator : TexList) { 38 | Texture* TheTexture = (Texture*)Iterator.second; 39 | 40 | if(TheTexture) { 41 | delete TheTexture; 42 | TheTexture = NULL; 43 | } 44 | } 45 | 46 | TexList.clear(); 47 | } 48 | 49 | //============================================================================= 50 | void TextureBank::AddTexture(SDL_Renderer* Renderer, std::string ID, std::string Filename) { 51 | if(ID == "") return; 52 | 53 | Texture* NewTexture = new Texture(); 54 | if(NewTexture->Load(Renderer, Filename) == false) { 55 | Log("Unable to Load Texture: %s", ID.c_str()); 56 | return; 57 | } 58 | 59 | TexList[ID] = NewTexture; 60 | } 61 | 62 | //----------------------------------------------------------------------------- 63 | Texture* TextureBank::Get(std::string ID) { 64 | if(TexList.find(ID) == TexList.end()) return 0; 65 | 66 | return TexList[ID]; 67 | } 68 | 69 | //============================================================================= 70 | -------------------------------------------------------------------------------- /TextureBank.h: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | /* 3 | Texture Bank class for loading multiple textures 4 | 5 | 3/18/2014 6 | SDLTutorials.com 7 | Tim Jones 8 | */ 9 | //============================================================================== 10 | #ifndef __TEXTUREBANK_H__ 11 | #define __TEXTUREBANK_H__ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include "Texture.h" 18 | 19 | class TextureBank { 20 | private: 21 | static std::map TexList; 22 | 23 | public: 24 | static bool Init(); 25 | 26 | static void Cleanup(); 27 | 28 | private: 29 | static void AddTexture(SDL_Renderer* Renderer, std::string ID, std::string Filename); 30 | 31 | public: 32 | static Texture* Get(std::string ID); 33 | 34 | static TextureBank* GetInstance(); 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | //============================================================================== 2 | /* 3 | Run the app! 4 | 5 | 3/11/2014 6 | SDLTutorials.com 7 | Tim Jones 8 | */ 9 | //============================================================================== 10 | #include "App.h" 11 | 12 | int main(int argc, char* argv[]) { 13 | return App::GetInstance()->Execute(argc, argv); 14 | } 15 | -------------------------------------------------------------------------------- /sdl-2.0-textures.cbp: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 49 | 50 | --------------------------------------------------------------------------------