-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
78 lines (67 loc) · 2.06 KB
/
main.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
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
78
#include <SDL.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
SDL_version version;
SDL_VERSION(&version);
printf("SDL version %d.%d.%d\n", version.major, version.minor, version.patch);
// Initialize SDL with video and game controller subsystems
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER) != 0)
{
printf("SDL initialization failed: %s\n", SDL_GetError());
return 1;
}
SDL_Window *window = SDL_CreateWindow(
"window",
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
720,
576,
SDL_WINDOW_FULLSCREEN);
if (window == NULL)
{
printf("Window creation failed: %s\n", SDL_GetError());
SDL_Quit();
return 1;
}
// SDL_Renderer * renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
if (renderer == NULL)
{
printf("Renderer creation failed: %s\n", SDL_GetError());
SDL_DestroyWindow(window);
SDL_Quit();
return 1;
}
SDL_Rect rect = {216, 96, 34, 64};
int running = 1;
SDL_Event event;
while (running)
{
if (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
running = 0;
break;
case SDL_CONTROLLERDEVICEADDED:
SDL_GameControllerOpen(event.cdevice.which);
break;
case SDL_CONTROLLERBUTTONDOWN:
if (event.cbutton.button == SDL_CONTROLLER_BUTTON_START)
running = 0;
break;
}
}
// Clear the screen
SDL_RenderClear(renderer);
// Draw a red square
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &rect);
// Draw everything on a white background
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderPresent(renderer);
}
return 0;
}