-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.c
More file actions
65 lines (56 loc) · 1.96 KB
/
Copy pathmain.c
File metadata and controls
65 lines (56 loc) · 1.96 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
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
int main(int argc, char *argv[]) {
// This prevents compiler warnings
// We don't actually need these variables, but they do need to be there so SDL_main works
(void)argc;
(void)argv;
// Initialize sdl
if(!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMEPAD)) {
SDL_Log("Couldn't initialize SDL: %s", SDL_GetError());
return 1;
}
SDL_Window * window = NULL;
SDL_Renderer * renderer = NULL;
if (!SDL_CreateWindowAndRenderer("window", 480, 272, 0, &window, &renderer)) {
SDL_Log("Couldn't create window/renderer: %s", SDL_GetError());
SDL_Quit();
return 2;
}
SDL_FRect square = {216, 96, 34, 64};
int running = 1;
SDL_Event event;
while (running) {
// Process input
if (SDL_PollEvent(&event)) {
switch (event.type) {
case SDL_EVENT_QUIT:
// End the loop if the programs is being closed
running = 0;
break;
case SDL_EVENT_GAMEPAD_ADDED:
// Connect a controller when it is connected
SDL_OpenGamepad(event.cdevice.which);
break;
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
if(event.gbutton.button == SDL_GAMEPAD_BUTTON_START) {
// Close the program if start is pressed
running = 0;
}
break;
}
}
// Clear the screen
SDL_RenderClear(renderer);
// Draw a red square
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &square);
// Draw everything on a white background
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderPresent(renderer);
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}