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
|
#include <SDL2/SDL.h>
#include <stdio.h>
#include <stdlib.h>
#include "util.h"
#include "sdlw.h"
#define sdl_clear(r) SDL_SetRenderDrawColor(r,0,0,0,0);\
SDL_RenderClear(r);
bw sdl_init(){
if(SDL_Init(SDL_INIT_VIDEO)<0){
err("failed to initialize sdl2 lib:(",pexit);
}
SDL_Renderer *r;
SDL_Window *w;
SDL_CreateWindowAndRenderer(400,400,0,&w,&r);
if(!w)
err("failed to create window",pexit);
sdl_clear(r);
SDL_RenderPresent(r);
//SDL_Delay(5000);
bw both;
both.w =w;
both.r =r;
return both;
}
void sdl_loop(bw w){
SDL_Event e;
//SDL_SetRenderDrawColor(w.r,255,0,0,255);
//for(int i = 0; i!=50;i++)
// SDL_RenderDrawPoint(w.r,i,i);
SDL_RenderPresent(w.r);
for(;;){
while(SDL_PollEvent(&e) > 0){
switch(e.type){
case SDL_QUIT:
return;
}
//SDL_UpdateWindowSurface(w.w);
}
}
}
void sdl_circle(bw w,int x, int y, int r){
SDL_SetRenderDrawColor(w.r,255,255,0,0);
for(int i = 1; i!=360; i++){
float cf = cosf(i);
float sf = sinf(i);
for(int z = 1; z<=r; z++){
int x2 = x + z * cf;
int y2 = y + z * sf;
SDL_RenderDrawPoint(w.r,x2,y2);
}
}
}
int main__2(){
bw b = sdl_init();
SDL_SetRenderDrawColor(b.r,255,255,0,0);
SDL_RenderDrawPoint(b.r,5,5);
sdl_loop(b);
return 0;
}
|