-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdl_functions.c
More file actions
77 lines (56 loc) · 1.66 KB
/
Copy pathsdl_functions.c
File metadata and controls
77 lines (56 loc) · 1.66 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
71
72
73
74
75
76
77
#include "main.h"
int random_int(int min, int max)
{
return min + rand() % (max - min);
}
void initSDL(Application *app)
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("Failed to initialise SDL: %s \n", SDL_GetError());
exit(1);
}
app->window = SDL_CreateWindow("Game Window", \
SDL_WINDOWPOS_UNDEFINED, \
SDL_WINDOWPOS_UNDEFINED, \
//the width of the window, in screen coordinates
640, \
//the height of the window, in screen coordinates
480, \
// 0, or one or more SDL_WindowFlags OR'd together
// used for things like resizable window, full-screen etc.
0);
if(!app->window)
{
printf("Failed to open %d x %d window: %s \n", SCREEN_WIDTH, SCREEN_HEIGHT, SDL_GetError());
exit(1);
}
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
app->renderer = SDL_CreateRenderer(app->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if(!app->renderer)
{
printf("Failed to create renderer: %s \n", SDL_GetError());
exit(1);
}
}
void prepareScene(Application *app)
{
SDL_SetRenderDrawColor(app->renderer, 0, 0, 255, 255);
SDL_RenderClear(app->renderer);
}
void presentScene(Application *app)
{
SDL_RenderPresent(app->renderer);
}
SDL_Texture *loadTexture(Application *app,char* fileName)
{
SDL_Texture *texture;
SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Loading %s", fileName);
texture = IMG_LoadTexture(app->renderer, fileName);
if(texture ==NULL){
printf("Cannot find texture %s \n", fileName);
SDL_Quit();
exit(1);
}
return texture;
}