-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTexture.cpp
More file actions
70 lines (55 loc) · 1.3 KB
/
Texture.cpp
File metadata and controls
70 lines (55 loc) · 1.3 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "Texture.h"
Texture::Texture() {}
Texture::Texture(SDL_Texture* resource, int width, int height,
SDL_Renderer* renderer)
: resource(resource),
width(width),
height(height),
renderer(renderer)
{
}
Texture::~Texture()
{
// Deallocate texture
std::cout << "Deallocating texture.\n";
SDL_DestroyTexture(resource);
}
// Fill the screen with this texture
void Texture::draw()
{
SDL_RenderCopy(renderer, resource, NULL, NULL);
}
// Draw the entire texture at the provided screenCoordinates
void Texture::draw(int screenX, int screenY)
{
SDL_Rect screenCoords;
screenCoords.x = screenX;
screenCoords.y = screenY;
screenCoords.w = width;
screenCoords.h = height;
SDL_RenderCopy(renderer, resource, NULL, &screenCoords);
}
void Texture::draw(int textureX, int textureY,
int textureWidth, int textureHeight,
int screenX, int screenY)
{
SDL_Rect texturePortion;
texturePortion.x = textureX;
texturePortion.y = textureY;
texturePortion.w = textureWidth;
texturePortion.h = textureHeight;
SDL_Rect screenCoords;
screenCoords.x = screenX;
screenCoords.y = screenY;
screenCoords.w = width;
screenCoords.h = height;
SDL_RenderCopy(renderer, resource, &texturePortion, &screenCoords);
}
int Texture::getWidth()
{
return width;
}
int Texture::getHeight()
{
return height;
}