-
Notifications
You must be signed in to change notification settings - Fork 0
/
texture.cpp
45 lines (37 loc) · 1.37 KB
/
texture.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "texture.h"
#include "global_variables.h"
#include <stdlib.h>
SDL_Texture* loadTexture( std::string path)
{
//The final texture
SDL_Texture* newTexture = NULL;
//Load image at specified path
SDL_Surface* loadedSurface = IMG_Load( path.c_str() );
if( loadedSurface == NULL )
{
printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() );
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
"Missing file",
"Texture image not found. Make sure there's an assets folder.",
window);
exit(1);
}
else
{
//Create texture from surface pixels
newTexture = SDL_CreateTextureFromSurface( renderer, loadedSurface );
if( newTexture == NULL )
{
printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
}
//Get rid of old loaded surface
SDL_FreeSurface( loadedSurface );
}
return newTexture;
}
void TextureContainer::initTextureContainer(){
marioAnimations = loadTexture("assets/textures/mario_animations.png");
marioBlocks = loadTexture("assets/textures/mario_blocks.png");
enemiesAnimations = loadTexture("assets/textures/enemies.png");
items = loadTexture("assets/textures/items.png");
}