-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGallery.cpp
More file actions
50 lines (44 loc) · 1.6 KB
/
Gallery.cpp
File metadata and controls
50 lines (44 loc) · 1.6 KB
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
46
47
48
#include "Gallery.h"
#include "SDL_utils.h"
#include <SDL.h>
#include <SDL_image.h>
Gallery::Gallery(SDL_Renderer* renderer_)
: renderer(renderer_)
{
loadGamePictures();
}
Gallery::~Gallery()
{
for (SDL_Texture* texture : pictures)
SDL_DestroyTexture(texture);
}
SDL_Texture* Gallery::loadTexture(std::string path )
{
SDL_Texture* newTexture = NULL;
SDL_Surface* loadedSurface = IMG_Load( path.c_str() );
if ( loadedSurface == NULL )
logSDLError(std::cout, "Unable to load image " + path + " SDL_image Error: " + IMG_GetError());
else {
newTexture = SDL_CreateTextureFromSurface( renderer, loadedSurface );
if( newTexture == NULL )
logSDLError(std::cout, "Unable to create texture from " + path + " SDL Error: " + SDL_GetError());
SDL_FreeSurface( loadedSurface );
}
return newTexture;
}
void Gallery::loadGamePictures()
{
pictures[0] = loadTexture("Image/Map/GrassGround.png");
pictures[1] = loadTexture("Image/Map/DLGround.png");
pictures[2] = loadTexture("Image/Map/DRGround.png");
pictures[3] = loadTexture("Image/Map/HGround.png");
pictures[4] = loadTexture("Image/Map/ULGround.png");
pictures[5] = loadTexture("Image/Map/URGround.png");
pictures[6] = loadTexture("Image/Map/VGround.png");
pictures[7] = loadTexture("Image/Map/Castle.png");
pictures[8] = loadTexture("Image/Map/Rock.png");
pictures[9] = loadTexture("Image/Map/Well.png");
pictures[10] = loadTexture("Image/Map/House.png");
pictures[11] = loadTexture("Image/Map/Grass.png");
pictures[12] = loadTexture("Image/Map/Log.png");
}