-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDL_Texture.c
50 lines (41 loc) · 1.02 KB
/
SDL_Texture.c
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
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "SDL_Error.h"
extern SDL_Texture *background;
extern int background_i;
SDL_Texture *loadTexture(char *file, SDL_Renderer *renderer)
{
SDL_Texture *texture = NULL;
texture = IMG_LoadTexture(renderer, file);
if (texture == NULL)
SDL_ErrorExit("could not load texture");
return texture;
}
void renderTextureWH(SDL_Texture *texture, SDL_Renderer *renderer, int x, int y,
int w, int h)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
dest.w = w;
dest.h = h;
SDL_RenderCopy(renderer, texture, NULL, &dest);
}
void renderTexture(SDL_Texture *texture, SDL_Renderer *renderer, int x, int y)
{
int w, h;
SDL_QueryTexture(texture, NULL, NULL, &w, &h);
renderTextureWH(texture, renderer, x, y, w, h);
}
void render_background(SDL_Renderer *renderer)
{
int x, y, h, w;
SDL_QueryTexture(background, NULL, NULL, &w, &h);
x = background_i;
y = 0;
for (; x <= 2000; x += w) {
renderTexture(background, renderer, x, y);
}
if (background_i > 1000)
background_i = 0;
}