-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdl2.c
90 lines (73 loc) · 2.24 KB
/
sdl2.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
79
80
81
82
83
84
85
86
87
88
89
90
#include <SDL2/SDL_log.h>
#include <SDL2/SDL_render.h>
#include <SDL2/SDL_timer.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_video.h>
#include <complex.h>
#include <math.h>
#include <stdio.h>
#include <SDL2/SDL.h>
int h, w;
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 360
#define WINDOW_XPOS 0
#define WINDOW_YPOS 0
int completedCircle = 0, radAngle, angle, xc, yc;
SDL_Event event;
SDL_Texture* texture = NULL;
SDL_Window* window = NULL;
SDL_Renderer* basic_renderer = NULL;
void drawCircle(int x, int y, int radius) {
if (!completedCircle) {
angle += 1;
printf("%i \n", angle);
radAngle = angle * (M_PI / 180);
xc = WINDOW_WIDTH / 2;
yc = WINDOW_HEIGHT / 2;
x = xc + radius * cos(angle);
y = yc + radius * sin(angle);
SDL_RenderDrawPoint(basic_renderer, x, y);
}
if (angle >= 360) {
completedCircle = 1;
printf("Pronto, seu círculo :)");
}
}
int main() {
int open = 1;
(SDL_GetWindowSize(window, &w, &h));
printf("A largura é : %i", w);
printf("A altura é: %i", h);
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
printf("irmao, tem alguma coisa errado com o sdl ae pae");
}
if (!window) {
//Se algo falhar, morre
SDL_DestroyRenderer(basic_renderer);
SDL_DestroyWindow(window);
SDL_Quit();
}
window = SDL_CreateWindow("WINDOW_NAME", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN);
basic_renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
SDL_RenderClear(basic_renderer);
SDL_SetRenderDrawColor(basic_renderer, 50, 50, 50, 255);
//Loop Principal
while (open) {
//Loop pra garantir que a janela feche e nao feche
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
open = 0;
}
}
//Renderizar circulo
drawCircle(320, 240, 100);
SDL_SetRenderDrawColor(basic_renderer, 255, 255, 255, 255);
//Dar um delay para que a cpu nn va fritar um ovo
SDL_RenderPresent(basic_renderer);
SDL_Delay(16);
}
SDL_DestroyRenderer(basic_renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}