Context* createContext(const char* title, int sizeX, int sizeY) { Context* context = NULL; context = malloc(sizeof(Context)); if (context == NULL) { error("Mauvaise alloc"); return NULL; } context->window = NULL; context->render = NULL; context->open = 0; context->window = SDL_CreateWindow(title,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,sizeX,sizeY,SDL_WINDOW_SHOWN); if (context->window == NULL) { errorSDL("Window"); return NULL; } else { context->open = 1; } context->render = SDL_CreateRenderer(context->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (context->render == NULL) { errorSDL("Renderer"); return NULL; } return context; }
SDL_Texture* loadImage(const string& path) { //loop("[Image Load] Loading Image."); if (renderer == NULL) { return NULL; } SDL_Surface* surface = IMG_Load( path.c_str() ); if( surface == NULL ) { errorSDL("[Image Load] Null Surface", SDL_GetError()); } SDL_SetColorKey (surface, SDL_TRUE, SDL_MapRGB(surface->format, 0xFA, 0xCF, 0xAC)); SDL_Texture* texture = SDL_CreateTextureFromSurface( renderer, surface ); if( texture == NULL ) { errorSDL("[Image Load] Null Texture", SDL_GetError()); } return texture; }