-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrenderUtils.cpp
49 lines (39 loc) · 1.34 KB
/
renderUtils.cpp
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
49
//
// renderUtils.cpp
// MyGame
//
// Created by August Trollback on 10/5/13.
// Copyright (c) 2013 August Trollback. All rights reserved.
//
#include "renderUtils.h"
SDL_Texture* SurfaceToTex(SDL_Surface* surface, SDL_Renderer* render){
SDL_Texture* texture = NULL;
texture = SDL_CreateTextureFromSurface(render, surface);
if(texture == NULL){
cout<<"Unable to convert surface to texture: "<<SDL_GetError()<<endl;
}
return texture;
}
void renderTex(SDL_Renderer *render, SDL_Texture *texture){
SDL_RenderCopy(render, texture, NULL, NULL);
}
void renderSurface(SDL_Renderer* render, SDL_Surface* surface){
SDL_Texture* texture = SDL_CreateTextureFromSurface(render, surface);
SDL_RenderCopy(render, texture, NULL, NULL);
SDL_DestroyTexture(texture);
}
SDL_Texture* loadTexture(string path, SDL_Renderer* renderer){
SDL_Texture* texture = NULL;
SDL_Surface* loadedSurface = IMG_Load(path.c_str());
if(loadedSurface == NULL){
cout<<"Unable to load image onto surface: "<<SDL_GetError()<<endl;
}
else {
texture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
if(texture == NULL){
cout<<"Unable to convert surface to texture: "<<SDL_GetError()<<endl;
}
SDL_FreeSurface(loadedSurface);
}
return texture;
}