-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGallery.cpp
More file actions
38 lines (34 loc) · 1.13 KB
/
Gallery.cpp
File metadata and controls
38 lines (34 loc) · 1.13 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
#include "Gallery.h"
#include "SDL_utils.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[PIC_CHERRY] = loadTexture("cherry.png");
pictures[PIC_SNAKE_VERTICAL] = loadTexture("snake_vertical.png");
pictures[PIC_SNAKE_HORIZONTAL] = loadTexture("snake_horizontal.png");
pictures[PIC_SNAKE_HEAD] = loadTexture("snake_head.png");
}