Arch Game Engine  0.2
image.cpp
1 #include "image.h"
2 
3 Image::Image() {}
4 Image::~Image() {}
5 void Image::loadImage(string file, SDL_Renderer* ren) {
6  if(file.substr(file.length() - 3) == "bmp") loadBMP(file, ren);
7  if(file.substr(file.length() - 3) == "png") loadPNG(file, ren);
8 }
9 SDL_Texture* Image::getTexture() {
10  return tex;
11 }
12 void Image::loadBMP(string file, SDL_Renderer* ren) {
13  filename = file;
14  SDL_Surface* surface = SDL_LoadBMP(file.c_str());
15  SDL_CHECK(surface, "SDL_LoadBMP(\"file.c_str()\")");
16  tex = SDL_CreateTextureFromSurface(ren, surface);
17  SDL_CHECK(tex, "SDL_CreateTextureFromSurface");
18  SDL_FreeSurface(surface);
19 }
20 void Image::loadPNG(string file, SDL_Renderer* ren) {
21  filename = file;
22  SDL_Surface* loadedSurface = IMG_Load(filename.c_str());
23  if(loadedSurface == NULL) {
24  printf("Unable to load image %s! SDL_image Error: %s\n", filename.c_str(), IMG_GetError());
25  } else {
26  tex = SDL_CreateTextureFromSurface(ren, loadedSurface);
27  if(tex == NULL) {
28  printf("Unable to create texture from %s! SDL Error: %s\n", filename.c_str(), SDL_GetError());
29  }
30  SDL_FreeSurface(loadedSurface);
31  }
32 }
void loadBMP(string file, SDL_Renderer *ren)
Load in a BMP image with the path to the BMP file and the renderer.
Definition: image.cpp:12
void loadImage(string file, SDL_Renderer *ren)
Load in either a BMP or PNG file with the path and renderer.
Definition: image.cpp:5
SDL_Texture * getTexture()
Get SDL_Texture.
Definition: image.cpp:9
void loadPNG(string file, SDL_Renderer *ren)
Load in a PNG image with the path to the PNG file and the renderer.
Definition: image.cpp:20