Skip to content

Instantly share code, notes, and snippets.

@Twinklebear
Created July 19, 2012 00:42
Show Gist options
  • Save Twinklebear/3139999 to your computer and use it in GitHub Desktop.
Save Twinklebear/3139999 to your computer and use it in GitHub Desktop.
#include "SDL.h"
#include "SDL_image.h"
#include <stdexcept>
#include <string>
#include <iostream>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
SDL_Renderer *renderer = nullptr;
SDL_Window *window = nullptr;
SDL_Texture* LoadImage(std::string file){
SDL_Texture* tex = nullptr;
tex = IMG_LoadTexture(renderer, file.c_str());
if (tex == nullptr)
throw std::runtime_error("Failed to load image: " + file + IMG_GetError());
return tex;
}
SDL_Texture *background = nullptr, *image = nullptr;
try {
background = LoadImage("../res/Lesson3/background.png");
image = LoadImage("../res/Lesson3/image.png");
}
catch (const std::runtime_error &e){
std::cout << e.what() << std::endl;
return 4;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment